Language Translation Package
Goals
- To provide a consistent language translation and localization library for CATS
- To create a portable nuget package library for language translation
- To make it easy for users to translate labels and strings in place
- To use user profiles defined in User Authentication and Authorization package
Background and strategic fit
CATS HUB module already has user interface translation feature in the form of administration module allowing users to translate terms (labels and string content) to language supported by CATS. Due to the need for this feature to be implemented in all CATS modules it is of great use if this feature is extracted into a separate package for ease of reuse.
Assumptions
- To define a consistent database schema to contain language and term translation content across all modules in CATS
- The package needs to create all required database objects inside the target application/module's database which shall be specified by a connection string again inside the target application config file
- The package should provide its own data access methods (prefereabley a small footprint ORM) to manage data stored inside language and terms tables
- It should allow consuming application to create as many languages as required
- It should not limit the number of terms to be translated
- It should allow in-place editing of strings from the user interface (Translation Mode)
Requirements
# | User Story Title | User Story Description | Priority | Notes |
---|---|---|---|---|
1 | Define Translation Language | As a system administrator I want to define new languages so that I can have CATS translated into as many lanaguages as I want | High | |
2 | Translate Terms/Strings | As a user I want to translate terms/strings from a CATS application so that I can have it in my preferred language. | ||
3 | Install Translation Package | As a developer I want an easy way of installing translation package so that I can use it from my application | ||
4 | Uninstall Package | As a developer I want the package to clean up itself and all resource it is using so that I can have my project reset into its original state when I uninstall the package. | ||
5 |
User interaction and design
Overview
Since translation/language seting is basic fitcherof the solution, it is reqired for the underling code to be flexable on language use. To accomplish this requirement required database is designed and the code to add new phrases, translate a given phrase to required language is achieved. This pakage will install basic code and configurations which will make it easy to get a phrase translated.
Content of the package
It is a class library project that have the required models and db configuration in it. It uses luselly cupled database as it was in the previous phase of the software development. The underling project is responsible to refere to the class liberaries of the packge. A service, Helper or extension methos is recommended to utilize the package.
Installation
As any Nuget Package, It can be installed from .Net package manager after setting the package source folder.
Known Issues
It required the existence of language, user Profile and translation database tables.
How it works
Add reference to the class as
using Edge.Translation.LanguageService; using Edge.Translation; //and define a class with an extension method like public static class LanguageConverterExtention { private static Database db = new Database("Translation"); //using the class liberary public static string TranslatePhrase(this HtmlHelper helper, string phrase) { phrase = phrase.Trim(); if (helper.ViewContext.HttpContext.User.Identity.IsAuthenticated) { string userName = helper.ViewContext.HttpContext.User.Identity.Name; userName = "admin"; //for test ourpus TranslationService ts = new TranslationService(); var language = db.SingleOrDefault<UserProfile>("select * from UserProfile where UserName=@0", userName).LanguageCode; string str = ts.GetPhrase(language, phrase); if (str != null) { return str; } else { Edge.Translation.Translation T = new Edge.Translation.Translation(); T.Phrase = phrase; T.LanguageID=language; T.TranslatedText = phrase; db.Insert(T); return ts.GetPhrase(language, phrase); } } else return phrase; } }
Questions
Below is a list of questions to be addressed as a result of this requirements document:
Question | Outcome |
---|---|