Set Up Internationalization
Introduction
RN Launchpad ❤️ Lingui. Lingui uses po files that are widely used by professional translators. Lingui makes using them seamless.
Setting Up the Languages
- In
/lib/constants.ts
, add or remove languages fromSUPPORTED_LANGUAGES
. - If you want to have a default language other than English, you can adjust
sourceLocale
in/lingui.config.js
- Adding new strings to translate is easy, the basic form is just
<Text>{t
A new phrase to translate.}</Text>
. - If you have added a new language or a new phrase, run
npm run extract
from the root directory of your project in your terminal. Lingui will automatically create a .po file for all your languages with all the strings of your project. Above each string you will see the place where it is used. - Once you have translated everything, run
npm run compile
, again from the root directory of your project in your terminal. Lingui will compile the .po files into .json files that will be used to display the translations. - If you save .tsx files anywhere other than
/app
or/components
, you will need to add the folder inlingui.config.js
.
What If You Don’t Need Internationalization?
If internationalization is not neededd, you have two options:
- Simply ignore it and do not display the language switcher component. The default language (English, unless specified otherwise) will be used.
- If you are certain you will never need translations, consider uninstalling Lingui and @formatjs tools from the project and replace all
{t`some string`}
withsome string
.
More Info
This only scratches the surface of what Lingui can do (pluralization, interpolation, formatting dates and numbers), of course. For more information, please check out the Lingui documentation.