react-native-i18n icon indicating copy to clipboard operation
react-native-i18n copied to clipboard

Translation not updating when changing language on iOS

Open SamBellerose opened this issue 6 years ago • 14 comments

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!

SamBellerose avatar Mar 20 '18 14:03 SamBellerose

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 avatar Mar 20 '18 15:03 Keped

@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.

SamBellerose avatar Mar 21 '18 16:03 SamBellerose

Yeah me too.

pontusab avatar Apr 06 '18 06:04 pontusab

Its working if I link the library manually in xcode.

pontusab avatar Apr 06 '18 08:04 pontusab

@pontusab is it working on Android for you?

SamBellerose avatar Apr 10 '18 20:04 SamBellerose

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 ?

howieyoung avatar Apr 26 '18 05:04 howieyoung

@SamBellerose @Keped @howieyoung it works for me with :

Did you add the langs in the localizations section ? capture d ecran 2018-06-06 a 17 20 44

padupuy avatar Jun 06 '18 15:06 padupuy

@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 avatar Jun 06 '18 17:06 SamBellerose

@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;
}

padupuy avatar Jun 07 '18 11:06 padupuy

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.

franzejr avatar Jun 21 '18 14:06 franzejr

This is still happening EN working fine any other language still not loading in iOS 11, working as expected in Android.

pabloga265 avatar Jun 22 '18 08:06 pabloga265

@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?

elribonazo avatar Jul 01 '18 10:07 elribonazo

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 :)

elribonazo avatar Jul 01 '18 10:07 elribonazo