Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using multiple translation files in aurelia i18N

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?

like image 548
Golden mole Avatar asked Sep 22 '15 18:09

Golden mole


1 Answers

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

like image 169
nemesv Avatar answered Dec 28 '22 06:12

nemesv