using multiple translation files in aurelia i18N

蹲街弑〆低调 提交于 2019-12-23 09:56:48

问题


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?


回答1:


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.

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

See also the documentation of i18next and this related github issue: Using namespaces



来源:https://stackoverflow.com/questions/32724138/using-multiple-translation-files-in-aurelia-i18n

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!