Top

INTERNATIONALIZATION (Language)

Welcome to React Native! React Native helps you build modern applications.

For getting started an React Native application you needs two things as Prerequisites.

Prerequisites

Before you begin, make sure your development environment includes React Native and install in Android Studio or in Visual Studio

Understand Language with Context STATE MANAGEMENT:


  1. react-i18next is a powerful i18n library for React and React Native that is based on i18next. It also has the most Github stars and download counts (see above) when compared to other i18n libraries for React Native, meaning that more people have been testing it on production, and there are more resources available for help when you get stuck.
  2. To install react-i18next and its dependency :
  3. Then, create the directory and files as shown below :

    en.json :

    zh.json :

    index.js :

    The resources variable contains all the translation strings imported from the JSON files we created earlier. However, it’s worth noting that these translation strings can also be managed through a UI, such as lociz — although it is not covered in this article, but if you are interested, you can check it out. lng variable sets the default language to be used in your app. fallbackLng specifies the fallback language if the value in lng is not available. interpolationLng on the other hand, specifies whether to escape values to mitigate XSS attacks.

    Note that index.js is not compulsory but is recommended to avoid cluttering up your App.js.

    Finally, App.js :

    Then in the Android simulator, you will see it is indeed working! :