react-native-i18n
react-native-i18n copied to clipboard
Translation not updating when changing language on iOS
I've followed the doc, installed the library with yarn
I have entered the command react-native link
And then restarted the package manager
I have tried this
import I18n from 'react-native-i18n';
I18n.fallbacks = true;
I18n.translations = {
'en': {
search: 'English',
},
'fr': {
search: 'France',
},
'fr-CA': {
search: 'Canada',
},
};
And then in my render
render() {
return (
<Input placeholder={I18n.t('search')} />
)
}
I have also added both french language in my project on XCode like it says to do in the ReadMe, when I run the project on an English emulator, the placeholder shows English as expected, but when I change the language to french, it still show English. Am I missing something?
Thanks!
Got the same problem here... FWIW, For me it's happening on iOS 11.x devices but not on 10.x ones (both simulator and real device)
@Keped I can confirm the same thing, I've downloaded other 10.x version of iOS simulator and it's working but it isn't on iOS 11.x devices.
Yeah me too.
Its working if I link the library manually in xcode.
@pontusab is it working on Android for you?
Same here, the emulator can show English as expected, but doesn't work with other languages (ex. zh) So, is it an issue from the version of IOS ?
@SamBellerose @Keped @howieyoung it works for me with :
Did you add the langs in the localizations section ?
@padupuy I'm using React-Native version 0.52.0 and I added the localizations, I'll try updating to the latest version of React-Native 0.55.0, maybe that will resolve the problem.
Thanks for the heads up!
@SamBellerose I notice something else ... I load my different translation files based on a shorter version of the I18N.locale
Here is my working code
import I18n from 'react-native-i18n';
// Enable fallbacks if you want `en-US` and `en-GB` to fallback to `en`
I18n.fallbacks = true;
// English language is the main language for fall back:
I18n.translations = {
en: require('./languages/en.json')
};
let currentLanguage = 'en';
let languageCode = I18n.locale.substr(0, 2);
// All other translations for the app goes to the respective language file:
switch (languageCode) {
case 'es':
I18n.translations.es = require('./languages/es.json');
currentLanguage = 'es';
break;
case 'fr':
I18n.translations.fr = require('./languages/fr.json');
currentLanguage = 'fr';
break;
case 'it':
I18n.translations.it = require('./languages/it.json');
currentLanguage = 'it';
break;
}
I'm having the same issue. I've added the Localizations and it seems the simulator and the real phone are always returning en
for the current locale.
This is still happening EN working fine any other language still not loading in iOS 11, working as expected in Android.
@padupuy Can you please tell me how did you add the elements there to xcode? I'm just unable to do that, tried a lot of different things but no success.
When I click on add, nothing appears... also the default language 'en' show's 0 strings.
My json files are added into /app/translations/locales/*.json , is that correct?
To all the people with issues on IOS. The linking is not working correctly on IOS so link the files manually and it will be able to get the correct language.
Fixed :)