React-native (Expo) 中的大型语言环境数据库

Big Locale DBs in React-native (Expo)

我找到了这篇简单易懂的文章 https://medium.com/@jamuhl/translate-your-expo-io-react-native-mobile-application-aa220b2362d2 来实现 RN 中的本地化(在 Expo 中)。

我的用例有点不同:我的应用程序有数百个要翻译的术语列表(每个语言约 1MB 的 js 对象,乘以 6-7 种语言)。

该应用完全离线(没有机会从服务器加载语言环境文件)所以我正在寻找延迟加载我想要的 json/js 语言环境对象的最佳方法。

我来这里是为了听取 RN/i18next 专家的建议。

编辑: 我几乎复制了这个 https://github.com/i18next/react-i18next/blob/master/example/react-native-expo/js/i18n.js

的 i18n 配置

真正的数据库在外地data:DB。 Obiouvsly 这不是加载大文件的最佳方式,我总是加载所有语言的所有数据库..我能以某种方式保持相同的简单结构但只延迟加载我需要的语言吗? 不然在i18next和react-native中有local lazy-load (from the device file system)的例子?

import i18n from 'i18next';
import {reactI18nextModule} from 'react-i18next';
i18n
    .use(languageDetector)
    .use(reactI18nextModule)
    .init({
        fallbackLng: 'en',
        resources: {
            en: {
                home: {
                    title: 'Welcome',
                    introduction: 'This text comes from i18next and is provided in english.',
                },
                data: { DB:require("./locales/it.json") },
            },
            de: {
                home: {
                    title: 'Willkommen',
                    introduction: 'Dieser Text ist von i18next und ist in deutsch.',
                },
                data: { DB:require("./locales/de.json") },

            }
        },
        // have a common namespace used around the full app
        ns: ['common'],
        defaultNS: 'home',

        debug: true,
        interpolation: {
            escapeValue: false, // not needed for react as it does escape per default to prevent xss!
        }
    });

使用 i18next 创建自己的后端实现相当简单...https://www.i18next.com/misc/creating-own-plugins#backend

我建议将您的翻译与应用程序捆绑在一起,而不是从任何外部资源加载。您还可以使用 https://www.i18next.com/overview/api#resource-handling

直接即时添加翻译