将i18next脱机用于react native



我们正在构建一个react原生应用程序,我们的客户希望我将其翻译成其他语言。

我们的计划是使用i18next无论发生什么,我们都必须保持它离线。。。我可以将i18next脱机用于react native吗?

谢谢,Vignesh

是的,你可以,实际上你可以"束";所有带有代码的翻译文件。这样,您就不会有任何http请求。

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');
});

对于更高级的解决方案,您可以围绕react本机fs编写一个i18next后端,它看起来应该类似于i18nextfs后端。(我自己没有尝试过这个选项(

最新更新