Translation feature
This feature can be used to define translations for the pages or applications that can be used to work automatically together with the language parameter from the url.
Translation file structure
The translation files are in json format and the language keys are expected to be in the iso 2 character codes.
{
"en": {
"key": "value"
},
"es": {
"key": "value"
}
}
Adding translations
Translations can be added on 2 different levels
- Application based translations
- Template based translations (page types only)
Application based translations
These are stored as separate files. New ones can be created from CREATE NEW -> Create new page and selecting the type translation.
These translations are only used by applications and the contents are shared between all the pages of the application once connected to one.
An application can also have multiple translation files. They are loaded in alphabetical order.
If 2 files contain the same key for the same language then the last loaded item will determine the used value.
Template based translations
These are stored on the templates (pages) and can only be used on the same template.
Translations can be added using the earth icon in the editor.
Template based translations will override application translations if both define the same key for a language.
Reading translations
Get in current language
This function uses the current navigation language code from url /en/ and used this to locate the language needed.
/000000/en/break-temp-6-page
{
"en": {
"key": "value"
}
}
{{ .Translation.Get “key“ }}
This would be loaded as “value” when the page is opened.
Get in specified language
This function takes in a second parameter for the language code we want to get the result for, this one ignores the url path language.
If the input language cannot be found then it default to the path parameter instead.
/000000/en/break-temp-6-page
{
"en": {
"key": "value"
}
}
{{ .Translation.GetIn “key“ “en“ }}
This would be loaded as “value” when the page is opened.
External source for translations
We can also use an external source for the translations, as long as it follows the same json structure. Values entered with this will overload the translations from both application and the template if they define the same key.
{{ .Translation.GetWithSource “key“ {"en": {"key": "value_1"}} }}
{{ .Translation.GetWithSourceIn “key“ “en“ {"en": {"key": "value"}} }}
Template load order
Load order determines what value is returned if there are multiple sources for translations
- Application based translations in alphabetical order
- Template based translation
- Custom source (if defined)
When a key is not found
If a key is not found then the key itself is printed.
Optional default
You can override this behaviour (where the key is returned when translation is not found) by settings a special value in the translations file. Using this the methods ‘Get’ and ‘GetWithSource’ will attempt to return the translation in the set default language when the translation for the initial language code is not found.
{
"default": {
"to": "en"
}
}
Translations optimization
There is also option to optimize huge translation files to one single file that will contain only translations that are actually used in the application. That feature would be useful for translation files larger than 1MB.
Configuring the optimization
To generate translation file and enable/disable it, just go to the application configuration, select templates section and click on the “Translations optimization” button.
Then need to generate the file by clicking on the “Generate optimal translations” button. This
action will generate a file in application with name {application UUID}-translation
Please
note: Optimization should be re-generated manually every time when at least one of the original
translation files were modified. Check the Enable optimized translations
option and confirm
the action to basically enable the feature.
Translation file generated in scope of main application and does not include translations from modules. If you have translations in modules, then they should contain only module specific translations, leaving huge translation files in main application. Translations from main application can be used inside modules.
When feature is enabled, GoErp will always use generated file instead of all application translation files.