Translations


We use i18n for translations, the idea of this approach to internalization is to make use of a method t(KEY) that takes in a key and later once the language is set it can figure out what value it needs to use depending on this language.

Traditionally one would find a .json file containing the mapping for each language taken into consideration, in our case the translations come from the back-office (drupal.getTranslations(Options)).

The issue

The issue is that the keys for internalization are introduced by the front-end, which means that the webmaster needs to go through the front end code and identify the keys they need to add into the _FRONTEND namespace in translations. This can be very tedious hard or simply not efficient enough.

Introduced fix

A solution is to scan the files automatically and generate a list of the keys. It detects and outputs them to a file with each key in a new line to be imported in the back-office.

Use : yarn workspace starter translate to generate the document, the output file will be named : translation/translation-output.txt.

Important Note : the DEV Server needs to be ran first before trying to extract the translations, since it scans .next folder.

Limitations

Using string interpolation (or variable interpolation, variable substitution, or variable expansion), this makes it not possible to extract the key since it depends on a variable. For this case the front-end should make a note for the possible keys somewhere in comments for example or the keys will have to be added manually later.

Example:

let some_key_1 = `Nx:${some_var}`
let some_key_2 = "nX: " + some_var
let some_key_3 = "nx: ".concat(some_var)