I am trying to implement i18next library to change React Native app language, but I am not able to translate it. enter image description hereI have created i18n.tsx file.
import i18next from 'i18next';import { initReactI18next } from 'react-i18next';import albanian from './al.json';import english from './en.json';i18next.use(initReactI18next).init({ initImmediate: false, lng: 'en', resources: { en: english, al: albanian }, react: { useSuspense: false }, interpolation: { escapeValue: false // react already safes from xss }});export default i18next;
al.json
{"WelcomeTexxt": "E vleresoj qe po e shikon kete video","Welcome": "Mire se vjen","Museum": "Muzeuuuu","welcomeBack": "MireseErdhe"}
en.json
{"welcomeTexxt": "I really appreciate you are watching","welcome": "Helloooooo","museum": "ooooooooooooooooo","welcomeBack": "Welcome Back 123455655"}
and the translation page
import React from 'react';import { View, Text, Button } from 'react-native';import '../lang/i18n';import { useTranslation } from 'react-i18next';import SwitchSelector from 'react-native-switch-selector';const options = [ { label: 'English', value: 'en' }, { label: 'Albanian', value: 'al' },];const LoginScreen = () => { const { t, i18n } = useTranslation(); console.log(t('welcome')); return (<View style={ { flex: 1, justifyContent: 'center' } }><Text>{t('welcomeBack')}</Text><SwitchSelector options={options} initial={0} onPress= {(language) => i18n.changeLanguage(language) } /><Text style={{ fontSize: 26, textAlign: 'center' }}>{t("WelcomeTexxt")}</Text><Text>{ t("Welcome") }</Text></View> );}export default LoginScreen;
Can anyone give me any ide why i18n.changeLanguage is not working to change the language? Thanks in advance