I am trying to implement localization for Expo React Native app.
My i18n.js file looks like this:
import { getLocales } from 'expo-localization';
import { I18n } from 'i18n-js';
// Set the key-value pairs for the different languages you want to support.
const i18n = new I18n({
en: { welcome: 'Hello' },
lt: { welcome: 'Labas' },
});
// Set the locale once at the beginning of your app.
i18n.locale = getLocales()[0].languageCode;
console.log(i18n.t('welcome'));
I did
npm install expo-localization
npx expo install i18n-js
And I launch with
npx expo start
I get error:
Cannot find native module 'ExpoLocalization', js engine: hermes
My versions in package-lock.json:
"i18n-js": "^4.4.3",
"expo-localization": "~15.0.3",
I also tried setting jsEngine in app.json:
"expo": {
"jsEngine": "hermes",
None of this really helped. Any suggestions?
2
Answers
Something was wrong with my project. I also needed maps but it didnt allowed me to use maps either. So I created new project using
And then it worked - I was able to add localization as well as maps.
The error mentions "ExpoLocalization", but the correct package name is expo-localization. There’s clearly a difference, and this could be causing the issue. We need more details on the error to be sure.
In the meantime, check your app.json to make sure it includes the plugin:
Try deleting node_modules and package-lock.json may be you used npm and yarn.
Update :
This how i use getLocales :
Try this and give me feedback.