See React-T for documentation.
- Add a new JSON file named with by language's IETF language tag, e.g.
pt-BR.json
. A list of common codes may come in handy. - 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('./json/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 the current user based on browser settings. A matching JSON language file is dynamically imported. Once it's loaded, the original phrase is replaced by T component with the translated one, provided that it was defined in a proper JSON file.