The vien angular admin template’s translation and language requirements are provided via @ngx-translate. Language entry files are located at src/lang folder and the app.component.ts file uses the init
function of shared/lang.service.ts file and provides it language options and default language.
Default language of the project is also set from the shared/lang.service.ts file with the defaultLanguage
variable. This variable should be the code
value of one of the items from the supportedLanguages
array.
These files are populated with the complete vocabulary of the vien angular admin template; many of which we are not going to use. As mentioned we are going to strip the template back to a walking skeleton and, during this process will group all the terms we need as a part of the translation service. Once the walking skeleton is complete we will remove all groups and terms we don’t need and this reduced set will be the core or our portals translation service.
The language files are json data structures and use collections of name value pairs to resolve the translated labels. For example, a pages collection might have three pages (home, system and user). The language file for this simple translation would be;
{
"pages": {
"home": "Home Page",
"system": "System Page",
"user": "User Page"
}
}
When the label for the pages.home element of the pages connection is required angular uses the various methods shown above to add the label. For example a home page title in a template would be as follows;
< h1 >{{ 'pages.home' | translate }}< /h1 >
The translator will take care of this at runtime and place “Home Page” in the template. Once we have the walking skeleton working we’ll start keeping a single en-US.json file and only ever use translated labels. That we, when we need to handle another language we can use the en-US.json as the dictionary.
Identifying our labels
In each collection in en-US.json we will add a CURRENT VALUES IN TEMPLATE element at the end of each collection and add the terms we are using below this line.
{
"pages": {
"videos": "Videos",
"vien": "Vien",
"visible": "Visible",
"wizard": "Wizard",
"--": "----- CURRENT VALUES IN TEMPLATE",
"home": "Home",
"terms": "Terms & Conditions",
"privacy": "Privacy"
}
}
When the walking skeleton is complete we will visit the en-US.json file and remove any collections not used and, if a collection is used, all the elements above and including the CURRENT VALUES IN TEMPLATE line.
This will then become our starting dictionary. The JSON ABC web site will be used to sort the file into alphabetical order.
How does the Template Handle an Unknown Element?
If the name/value pair pages.invoice does not exist in the en-US.json pages collection, the language sub-system will simply display pages.invoice in the label and the missing element can be added to the collection.