Difference between revisions of "Translations"
| Line 35: | Line 35: | ||
You can use the translation service to auto generate translation values from the application modules, this will locate any translatable elements in the current applications UI modules and add entries into the database, if there are locale.xx.json files for the module then these can also be optionally imported. | You can use the translation service to auto generate translation values from the application modules, this will locate any translatable elements in the current applications UI modules and add entries into the database, if there are locale.xx.json files for the module then these can also be optionally imported. | ||
This is useful when you have a new project or have created lots of new modules and want to extract the elements for translation. | |||
First you need to update the translation service config as below | First you need to update the translation service config as below | ||
Revision as of 16:03, 2 September 2022
Getting Started
Translations can come from a variety of sources, this is meant as a getting started guide to adding and managing translations in social stack
Directly added to the database via the admin panel
You can use the admin panel to add entries manually to any entities which have localised fields, there is also the translation table which holds translatable text from within UI modules.
Embedding translations into UI Modules
To add some translatable text to a module it needs to be wrapped in `` quotes so for example
`Feed` or `${data} Feed`
where the data element would be injected at runtime.
Default translations for a module (only available when hosted locally/DEV)
You can add default translations into locale.xx.json files as part of UI modules where xx is the locale code, so for example 'it'.
{
"Feed" : "Attività",
"News" : "Notizia"
}
These files are processed when the page builder (UIBundle) is run locally to build the core page bundle and inject any translations.
They are used as the default but may be replaced by values from the database translations table, this will only happen locally as when deployed these files will not be available, they can however be loaded into the database for deployment as explained below.
These files allow baseline translations to be stored as part of the module itself and be imported into the database as explained below
Auto generating translation table entries (only available when hosted locally/DEV)
You can use the translation service to auto generate translation values from the application modules, this will locate any translatable elements in the current applications UI modules and add entries into the database, if there are locale.xx.json files for the module then these can also be optionally imported.
This is useful when you have a new project or have created lots of new modules and want to extract the elements for translation.
First you need to update the translation service config as below
{
"ReformatCanvasElements": false,
"AutoAddBaseLineTranslations": true,
"AutoAddTranslationElements": true,
"AutoAddExcludeModules" : [
"Admin/Dashboards/Database",
"Admin/Layouts/MediaCenter",
"Admin/AutoList",
"Admin/AutoForm",
"Admin/CanvasEditor/RichEditor",
"Admin/Layouts/Dashboard",
"Admin/Dashboards/Developer",
"Admin/PermissionGrid",
"Admin/Dashboards/StressTest"
]
}
If AutoAddBaseLineTranslations is true then any locale.xx.json files will be processed and their values added into the translations table.
if AutoAddTranslationElements is true then any translatable items found when parsing the UI modules will be added, you can add exclusions as above to ignore any backend modules for example.
To perform the auto generation, login as an admin user and run the following url
/v1/translation/prepopulateAny messages will be written to stdout
Exporting po files for translation
Once you have your entries in the database you can export a pot file and use it to easily create the localised values for the languages supported by your application
For each table you need to run a request to generate the po file
To perform the auto generation, login as an admin user and run the following url
/v1/{entityTypeName}/list.potSo for example with the translation table it would be /v1/translation/list.pot
The output file can be opened in a suitable editor such as po edit which can be downloaded from https://poedit.net/
Once translated the generated file can be loaded back into the platform
Importing translated po files
Once we have a translated po file it can be loaded into the platform, there are currently 2 options for this
Mass import of translation files (only available when hosted locally/DEV)
If it is just entries relating to the translation table they can be copied into the /translation folder in the root of the application and loaded using a helper url in the translation service (this may be get extended to other entities as time allows)
copy any po files into the /Translations folder in the root of the solution (you may need to create this)
To perform the load, login as an admin user and run the following url
/v1/transation/potfilesThe progress will get written to stdout
Upload the po files via the admin UI
The alternative is to use the admin panel to upload and process the po files, this is currently the ONLY option for non translation table entries and is useful if you need to update a remote site
You may need to import the admin UI module
socialstack install Admin/Translation/Upload
To perform the import, login as an admin user and load the following page
/en-admin/translation/uploadEnter the name of the entity you are loading (this is a safety check)
Upload the po file
Click the button to start the process
Once it has completed some stats will be returned showing how may items were updated etc