EDENMOBILE I18N
Table of Contents
Framework
EdenMobile integrates the angular-translate module for translation of UI strings.
Translatables
To make an HTML text node translatable, use the translate
attribute to identify the message:
<!-- untranslated --> <h2>Settings</h2> <!-- translatable --> <h2 translate="Settings"></h2>
Alternatively, this can be written in AngularJS filter notation:
<!-- untranslated --> <h2>Settings</h2> <!-- translatable --> <h2>{{"Settings" | translate}}</h2>
For use in controllers, see: https://angular-translate.github.io/docs/#/guide/03_using-translate-service (we will implement a convenient wrapper for this)
Language Files
Language files are located in the www/i18n
folder.
The naming pattern for language files is <language key>.json
, where the language key is a 2-letter ISO-639-1 language code (lowercase), optionally followed by a regional variant identifier (separated by underscore):
en.json
All recognized language keys must be registered in www.js/i18n.js
:
$translateProvider .fallbackLanguage('en') .registerAvailableLanguageKeys(['en', 'sv'], { 'en_US': 'en', 'en_UK': 'en', 'en_GB': 'en', 'sv_SE': 'sv' }) .determinePreferredLanguage(); }
The active language is determined from system settings. If no corresponding translation file can be found, en.json
will be used.
Language files are JSON with the following format:
{ "Message_key": "Translated" }
Unlike in Sahana Eden, the Message_key is not the untranslated message, but a unique key for the message (must not contain blanks!).
The message key should be a shorthand for the actual message (normal case, reasonable length), with multiple words separated by underscores:
{ "Single": "This is a single word message key", "Two_words": "This is a message key consisting of two words" }
Where the message contains variables, this should be indicated in the message key with a plus sign followed by the variable name (all-uppercase):
{ "Message_with_variable+NAME": "A message including the variable {{name}}" }
Other conventions
- Use double quotes for both keys and translations
- Remember to not leave a trailing comma after the last message in the file (=invalid JSON!)