| | 1 | = EDENMOBILE I18N = |
| | 2 | [[TOC]] |
| | 3 | |
| | 4 | == Framework == |
| | 5 | |
| | 6 | !EdenMobile integrates the [http://angular-translate.github.io angular-translate] module for translation of UI strings. |
| | 7 | |
| | 8 | == Translatables == |
| | 9 | |
| | 10 | To make an HTML text node translatable, use the {{{translate}}} attribute to identify the message: |
| | 11 | |
| | 12 | {{{ |
| | 13 | <!-- untranslated --> |
| | 14 | <h2>Settings</h2> |
| | 15 | |
| | 16 | <!-- translatable --> |
| | 17 | <h2 translate="Settings"></h2> |
| | 18 | }}} |
| | 19 | |
| | 20 | Alternatively, this can be written in AngularJS filter notation: |
| | 21 | |
| | 22 | {{{ |
| | 23 | <!-- untranslated --> |
| | 24 | <h2>Settings</h2> |
| | 25 | |
| | 26 | <!-- translatable --> |
| | 27 | <h2>{{"Settings" | translate}}</h2> |
| | 28 | }}} |
| | 29 | |
| | 30 | For use in controllers, see: [https://angular-translate.github.io/docs/#/guide/03_using-translate-service] (we will implement a convenient wrapper for this) |
| | 31 | |
| | 32 | == Language Files == |
| | 33 | |
| | 34 | Language files are located in the {{{www/i18n}}} folder. |
| | 35 | |
| | 36 | 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): |
| | 37 | |
| | 38 | {{{ |
| | 39 | en.json |
| | 40 | }}} |
| | 41 | |
| | 42 | All recognized language keys must be registered in {{{www.js/i18n.js}}}: |
| | 43 | |
| | 44 | {{{ |
| | 45 | $translateProvider |
| | 46 | .fallbackLanguage('en') |
| | 47 | .registerAvailableLanguageKeys(['en', 'sv'], { |
| | 48 | 'en_US': 'en', |
| | 49 | 'en_UK': 'en', |
| | 50 | 'en_GB': 'en', |
| | 51 | 'sv_SE': 'sv', |
| | 52 | }) |
| | 53 | .determinePreferredLanguage(); |
| | 54 | } |
| | 55 | }}} |
| | 56 | |
| | 57 | The active language is determined from system settings. If no corresponding translation file can be found, {{{en.json}}} will be used. |
| | 58 | |
| | 59 | Language files are JSON with the following format: |
| | 60 | |
| | 61 | {{{ |
| | 62 | { |
| | 63 | "Message_key": "Translated" |
| | 64 | } |
| | 65 | }}} |
| | 66 | |
| | 67 | Unlike in Sahana Eden, the '''Message_key''' is not the untranslated message, but a unique key for the message (must not contain blanks!). |
| | 68 | |
| | 69 | The message key should be a ''shorthand'' for the actual message (normal case, reasonable length), with multiple words separated by underscores: |
| | 70 | |
| | 71 | {{{ |
| | 72 | { |
| | 73 | "Single": "This is a single word message key", |
| | 74 | "Two_words": "This is a message key consisting of two words" |
| | 75 | } |
| | 76 | }}} |
| | 77 | |
| | 78 | Where the message contains variables, this should be indicated in the message key with a plus sign followed by the variable name (all-uppercase): |
| | 79 | |
| | 80 | {{{ |
| | 81 | { |
| | 82 | "Message_with_variable+NAME": "A message including the variable {{name}}" |
| | 83 | } |
| | 84 | }}} |
| | 85 | |
| | 86 | == Other conventions == |
| | 87 | |
| | 88 | - Use double quotes for both keys and translations |
| | 89 | - Remember to '''not''' leave a trailing comma after the last message in the file (=invalid JSON!) |