Using multiple translation files in aurelia i18N

I have a working application using aurelia-i18n. I would like to split the translation.json file into several files like nav.json, message.json etc., but I'm not sure how to do this.
Here's what it looks like now.

locale |-en |- translation.json 

But I want to change it that way.

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

Can this be done? If so, how do I configure it and access the values ​​in each file?

+5
source share
1 answer

You can have multiple resource files, and they are called namespaces in the i18next library (by default, you have only one namespace called: translation ), which is used by aurelia i18N .

You just need to specify your namespaces when configuring the plugin with the namespaces and defaultNs 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 i18next documentation documentation and this related github issue: Using the Namespace

+6
source

Source: https://habr.com/ru/post/1232046/


All Articles