Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

localization - 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...