如何模块化 i18n 文件

How to modularize i18n files

我对 i18n 完全陌生。现在开始构建我的 React Native 应用程序以进行翻译。

应用程序中的大部分元数据来自服务器按需作为描述特定模块结构的 json 文件。一个典型的客户端可能有大约 5 到 50 个这样的 "modules" 加载到它的 Redux 存储中。

一种模块类型如下所示(简化):

{
  id: 5,
  modifiedAt: new Date('2017-02-22T09:50:50.212+0100'),
  name: 'Module name',
  version: '1.0.0',
  definition: {
    preconditions: {},
    actions: {},
    effects: {},
    fieldDefinitions: {
      room: {
        title: 'Field title for "room"',
        warning: 'Room is missing',
        helpText: 'Enter room id/name',
        type: 'string',
        isRequired: true,
      },
    ui: {
      title: 'Module title, i.e. title on input form',
      menuItem: {
        iconName: 'md-settings',
        iconLibrary: 'Ionicons',
        iconColor: null,
        sortOrder: 99,
      },
      sections: [
        {
          id: 'ed472749-ec3d-4b72-9ce9-f88ee703b2cf',
          title: 'Installation',
          isRequired: true,
          formFields: ['room', ...],
        },
        {
          id: 'c070bfdf-88f1-423a-8854-b47b154c2359',
          title: 'Photo before started repair',
          isRequired: true,
          sectionType: 'media',
        }
      ],
    },
  },
  jsonSchema: {
    //schema to validate form output before saving
    //also used by API before saving to database
  },
  i18n: {
    en: {

    },
    de: {

    }
  }
};

我在 json 的末尾添加了 18n,因为这是我目前的尝试。可以为特定客户定制模块。我认为将 i18n 封装到每个模块中会很好。

我正在考虑为此使用 react-i18next,因为它似乎有据可查,并且在我需要翻译我的 Express 站点时也可以使用。

我也在考虑给每个模块一个唯一的 guid,我可以在应用程序加载每个 i18n 文件时将其用作命名空间 ID。

这是模块化 i18n 文件的合理方法吗?

我搜索了 i18n 教程,但我只找到了特定语言的教程。任何人都可以推荐一本关于选择什么结构、如何使用命名空间、如何模块化等的很好讨论的国际化入门

我们个人围绕特性命名空间(拆分)i18n 文件 - 可能反映您的模块....将每个模块拆分为一个文件并没有什么不好 - 但如果变小,您可能会将它们合并为更大的文件.. .真的取决于你的项目的大小。

我们制作了一些 documentation/tips 用于在 https://docs.locize.com/namespaces.html 上复制文件(locize.com - 是 i18next 的服务层,由与 i18next 相同的人提供(我 ;)) )