Internationalization (i18n) system
Documenting how we handle translations in the code
Last updated
Was this helpful?
Documenting how we handle translations in the code
Last updated
Was this helpful?
We use to manage our translations. They are extracted from the code to src/lang/${locale}.json
files using the npm run build:langs
command (CI will notify you if the translation files are outdated). Don't translate the strings directly in the files, we use to manage our translatations.
Example
defaultMessage
string breakdown:
action
variable name
select
keyword
delete
and archive
possible values
other
all other values will use this key
An exception to this rule: very common enums or the ones with many possible values should be implemented as a separate file listing all values because:
Re-usability
A map of translations is easier to read than a long select string with tons of options
The order of the words may change from a language to another. For this reason we must always pass the values to be replaced in values
so their order can later be changed.
Example
Splitting a string is alway problematic, because translators loose the context: the strings may not be next to each others when they'll be translated.
In many Latin languages, the translation for a string like "Created at" will depend on the context because of the feminine/masculine forms. The best way to provide this context is to set an ID on the string:
In some parts of the code we translate links like this:
This is bad because we're creating two strings and translators loose the context when they translate one. You should do this instead:
The FormattedMessage
component is the main way to translate strings. To use it, you just need to add the following import:
Then you just add the component with an unique id
and a defaultMessage
.
For VSCode users, you can use the following snippet to make your life easier:
See as an example.
Just go to , click on Target languages
pick the language and click Update
.
To activate a language on the website, we usually wait to have a correct translated ratio (20-30%). Then activate it by adding a new line in .