Translation for Skosmos 3 - NatLibFi/Skosmos GitHub Wiki
Translation of the Skosmos 3 user interface is handled using the following infrastructure:
- In the Skosmos PHP backend, translations are managed using Symfony Translation.
- In the frontend code, Vue i18n is used (WIP, see #1523)
- To manage the translations to different languages, we use the Lokalise platform.
The base/default language for all messages is English, so messages in the Skosmos codebase (e.g. Twig templates and Vue templates) are in English. Translations to all other languages are maintained using Lokalise.
In the Skosmos application code, translations are saved in JSON files under resource/translations
. The files are named messages.XX.json
, where XX is the BCP47 language code.
Editing existing translations
TBW. Use Lokalise.
Translating Skosmos to a new language
TBW. Use Lokalise.
Maintaining translations when the code changes
When the code changes, the translations need to keep up. The way to ensure this is to extract the messages from the codebase and synchronize the changes to Lokalise, then pull back the translations from Lokalise to the codebase.
When new messages are needed
1. Make a change in the code that adds a new translated message into the twig templates
2. Check that it can be extracted:
bin/console translation:extract --dump-messages en
(should be shown in the list) or
bin/console debug:translation en
(should show it as missing)
3. Extract the message(s) and add them to the English language translation file:
bin/console translation:extract --force en --format json --prefix ""
4. Push the translation file to Lokalise:
bin/console translation:push lokalise --domains messages --locales en --force
5. In the Lokalise UI, look up the message and add translations in other languages
6. Pull the translations back to the codebase:
bin/console translation:pull lokalise --domains messages --format json
Note! It is possible that a key-value pair removed in Lokalise does not get deleted from the local English (default) language file as a result of the pull
command. In that case the --force
option could be used to remove the key-value pair, but it would delete all the pairs where both the key and value are the same (e.g. 'Error': 'Error').
Therefore, it is better to manually remove from the local file any key-value pairs that have been removed in Lokalise. The issue is known and a solution will be sought later.
Removing obsolete messages
This command shows unused messages:
bin/console debug:translation en
However, currently it can only see messages used in Twig templates, not elsewhere in the code. So the "unused" status cannot be relied upon.
TBW: how to remove unneeded messages from the translation files and from Lokalise