Translations and Snippets
How the game texts are translated and how to change them from the admin panel. The translations are the snippets feature (enabled in Features).
How the texts are resolved
- Every text of the game UI has a key, for example chat.tabs.message ("General") or rewards.dailyLogin ("Daily Login"). The default English texts are in the client translations of each feature (lib/[feature]/client/snippets/en_US.js).
- The Translations > Snippets rows are loaded when the server starts and replace the default text of the same key and locale, so a text can be changed without touching the code.
- The values can have placeholders that the game replaces, for example %playerName in chat.joinedRoom or %loginCount in rewards.straightDaysLogin; keep them in the new text.
For example, to rename the general chat tab add a snippet for en_US with the key chat.tabs.message and the value Room, and restart the server:
Adding a language
- Open Translations > Locales and create the locale, for example es_ES with the Language Code es and the Country Code ES.
- Add the Snippets of that locale for every key. The default texts only exist for en_US: a key without a snippet in the player locale is shown as the key itself.
- Assign the locale to the users in Users > Users Locale; the users without a row use en_US.
- Restart the server.
With more than one locale the game settings show a language selector (the translator.* texts), but in the current version the server does not save the selected language: set the locale of the users in Users Locale.
Code integration (advanced)
- Server: SnippetsPlugin (lib/snippets/server/plugin.js) loads the locales and snippets into the client config on reldens.serverBeforeListen (ConfigurationEnricher) and adds the user locale to the initial game data (InitialGameDataEnricher, with the reldens.beforeEnrichUserWithLocale and reldens.afterEnrichPlayerWithLocale events).
- Client: each feature registers its default texts with TranslationsMapper.forConfig() and the Translator (lib/snippets/translator.js) resolves them with gameManager.services.translator.t(key, params).
- See Snippets Entity, Locale Entity and Users Locale Entity.
reldens