- Define translatable string in the code:
<T>Original phrase</T>
- If you're the translator, add an entry in language JSON files, for example:
You don't need to add anything for a new en-US string.
{ "Original phrase": "Przetłumaczona fraza" }
- Add a new JSON file named with by languages's IETF language tag, e.g.
pt-BR.json
. - Take one of the previously set up JSONs to copy all the keys of the strings that need translations and fill in your JSON with translated phrases.
- In
i18n.js
, add JSON file to the list of imports inlanguageFiles
, e.g.'pt-BR': import('./pt-BR.json'),
. - Verify that strings are loaded correctly by running the project locally.
getMatchingLocale
function returns a locale that is a preferred one for current user based on browser settings. Matching JSON language file is dynamically imported. Once it's loaded, original phrase is replaced by T component with translated one, provided that it was defined in proper JSON file.