GAS Basics / Internationalization |
Add your custom translation texts in the locale file and reference them in the HTML code in the widget template file.
The Genero Web Client for JavaScript (GWC-JS) front-end provides support for language selection based on locale. This topic details how you can use translation texts to provide localization mainly to text in the following GWC-JS front-end components:
You will find the locale files in your project_dir/src/locales/xx-YY.json, where "xx-YY" follows the standard localization code used for languages, for example, en-US, de-DE, fr-FR, etc.
Locale files are json files which have a typical json structure of keys and values in quotes separated by colons, ":". A sample from the US English locale file is shown.
{ "gwc": { "lngName" : "English", "app": { […] "waiting": "Waiting for connection", "restart": "Restart the same application", "run": "Run", […] }
data-i18n="key"Where "key" is the localization key in the locale file.
<span class="…" data-i18n="gwc.app.restart">Restart the same application</span>
GWC-JS will replace the text "Restart the same application" within the <span> element with that referenced by the gwc.app.restart key in the locale file. If the key is not found, the GWC-JS falls back to the default locale, "en-US". If the entry is still not found, then the translation value will be the key name.
Internationalization is done by the GWC-JS JavaScript function i18n.t. This function takes the localization key as argument and returns the translation text.
i18n.t('gwc.app.restart')
Figure 1. GWC-JS User Interface Menus
Figure 2. Stored Settings configuration Window
{ "gwc": { "lngName" : "English", […] }