Search code examples
react-nativelocalizationtranslatei18nextreact-i18next

Using i18next offline for react native


We are building an react native app and our customers wants me to translate it into other languages.

Our plan is to use i18next We have to keep it offline no matter what... Can I use i18next offline for react native?

Thanks, Vignesh


Solution

  • Yes you can, actually you can "bundle" all translation files with the code. this way, you won't have any http requests.

    import i18next from 'i18next';
    import enTranslations from '../path/to/locales/en/translations.json';
    import deTranslations from '../path/to/locales/de/translations.json';
    
    i18next.init({
      lng: 'en',
      debug: true,
      resources: {
        en: {
          translation: enTranslations  // <---- your english translations
        },
        de: {
          translation: deTranslations
        }
      }
    }, function(err, t) {
      // initialized and ready to go!
      document.getElementById('output').innerHTML = i18next.t('key');
    });
    

    For more advanced solution, you can write an i18next Backend around react-native-fs it should look similar to i18next-fs-backend. (I didn't tried this option it my self)