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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With