react-native-localize we need to detect the device language
Setup in project
In the root off your React Native project add a folder "translations"
Now create a new Typescript file in this folder called "i18n.ts"
importi18nfrom'i18next';import{initReactI18next}from'react-i18next';import{getLocales}from'react-native-localize';importENfrom'./en.json';i18n.use(initReactI18next).init({ resources:{ en:{translation:EN},}, lng:getLocales()[0].languageCode,// Get the first device language fallbackLng:'en', compatibilityJSON:'v3',// By default React Native projects does not support Intl});exportdefault i18n;
Add a JSON file in the same folder called "en.json"
{"TITLE":"React Native",}
Import the i18n.ts file in your App.tsx to initialise the setup
import'./translations/i18n';
Now you all done! You can start using i18next functionality in your entire project.
Hinting Typescript (optional)
You can have hinting tips for your translations keys so you don't use a key that doesn't exist.