代码之家  ›  专栏  ›  技术社区  ›  Michael

如何模块化i18n文件

  •  1
  • Michael  · 技术社区  · 7 年前

    {
      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: {
    
        }
      }
    };
    

    我正在考虑使用react-i18next,因为它似乎有很好的文档记录,并且在我需要翻译我的Express站点时也会起作用。

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

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

    我搜索了i18n教程,但最终只找到了特定语言的教程。有谁能推荐一本i18n入门书,并对选择何种结构、如何使用名称空间、如何模块化等进行充分讨论吗。

    1 回复  |  直到 7 年前
        1
  •  1
  •   jamuhl    7 年前

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

    我们制作了一些文档/提示,用于在 https://docs.locize.com/namespaces.html