【问题标题】:using multiple translation files in aurelia i18N在 aurelia i18N 中使用多个翻译文件
【发布时间】:2015-12-19 20:38:32
【问题描述】:

我有一个使用 aurelia-i18n 的工作应用程序。我想将 translation.json 文件拆分为多个文件,如 nav.json、message.json 等,但我不知道该怎么做。
这就是它现在的样子。

locale
  |-en
     |- translation.json

但我想把它改成这样。

locale
  |-en
     |- nav.json
     |- message.json

有可能吗?如果是这样,我该如何配置它并访问每个文件中的值?

【问题讨论】:

    标签: aurelia i18next


    【解决方案1】:

    您可以拥有多个资源文件,它们在i18next library 中称为命名空间(默认情况下,您只有一个命名空间,称为:translation),供aurelia i18N 使用。

    您只需在使用ns 选项内的namespacesdefaultNs 属性配置插件时列出您的命名空间:

    .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
            });
          });
    

    另请参阅documentation of i18next 和这个相关的 github 问题:Using namespaces

    【讨论】:

    • 它回答了如何使用不同文件的命名空间。但不要使用多个文件。
    猜你喜欢
    • 2019-01-05
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    • 1970-01-01
    • 2018-09-15
    • 1970-01-01
    相关资源
    最近更新 更多