在aurelia i18N中使用多个翻译文件 [英] using multiple translation files in aurelia i18N
问题描述
我有一个正在使用aurelia-i18n的应用程序.我想将translation.json文件拆分为多个文件,例如nav.json,message.json等,但我不确定如何执行.
这就是现在的样子.
I have a working app using aurelia-i18n. I would like to split translation.json file into multiple files like nav.json, message.json, etc but I am not sure how to do it.
This is how it looks right now.
locale
|-en
|- translation.json
但是我想将其更改为这种方式.
But I want to change it to this way.
locale
|-en
|- nav.json
|- message.json
有可能做到吗?如果是这样,我该如何配置它并访问每个文件中的值?
Is it possible to do it? If so, how do I configure it and access values in each file?
推荐答案
您可以有多个资源文件,这些文件在 aurelia i18N .
You can have multiple resource files and these are called namespaces in the i18next library (by default you only have one namespace which is called: translation
) which is used by aurelia i18N.
使用ns
选项中的namespaces
和defaultNs
属性配置插件时,您只需要列出名称空间:
You just need to list your namespaces when configuring the plugin with the namespaces
and defaultNs
properties inside the ns
option:
.plugin('aurelia-i18n', (instance) => {
// adapt options to your needs (see http://i18next.com/pages/doc_init.html)
instance.setup({
resGetPath : 'locale/__lng__/__ns__.json',
lng : 'de',
attributes : ['t','i18n'],
ns: {
namespaces: ['nav', 'message'],
defaultNs: 'message'
},
getAsync : true,
sendMissing : false,
fallbackLng : 'en',
debug : false
});
});
另请参阅 i18next的文档和相关的github问题:
See also the documentation of i18next and this related github issue: Using namespaces
这篇关于在aurelia i18N中使用多个翻译文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!