我对i18n完全陌生。现在开始构建我的React Native应用程序以进行翻译。
应用程序中的大多数元数据来自服务器,需要作为描述某个模块结构的json文件。一个典型的客户可能有大约5到50个这样的"模块"加载到它的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文件时,我可以将其用作namespace-id。
这是模块化i18n文件的合理方法吗?
我已经搜索了i18n教程,但我最终只能使用特定语言的教程。任何人都可以推荐i18n入门,对选择何种结构,如何使用命名空间,如何进行模块化等进行讨论。
答案 0 :(得分:1)
我们个人命名(拆分)i18n文件的功能 - 可能反映你的模块....每个模块分成一个文件没有什么不好 - 但如果变小,你可能会将它们合并到更大的文件...真的取决于项目的大小。
我们在https://docs.locize.com/namespaces.html(locize.com - 作为i18next的服务层,由i18next(me;))提供的文件中提供了一些文档/提示。