Reputation: 10646
I have a node application which uses the i18next module to handle i18n, but I'm having one problem that I can't seem to solve on the server side.
The application is built in node
and uses the express
framework.
In the main app.js
file that is the entry point for the ap I require the i18n
module and run the init
method.
This is to set it up for use on the client side.
Later on in a different file I am trying to reset the resGetPath
property in order to load a translation file in a different location to the normal ones (some files are located in the default locales/__lng__/__ns__.json
path, others are in their own separate folders).
I can't seem to find a specific method on the i18n
object to do this so I have been trying to just run the init
method again with the callback.
However even if I do this the resGetPath
property is not changed and it doesn't pick up the translation strings from the new files.
If I set the resGetPath
property in the first init
call in app.js
though it works as expected (although then it loses the normal translations in locales/__lng__/__ns__.json
)
Basically this is what I'm trying to do:
app.js
i18n.init({
detectLngQS: 'lang',
debug: false,
useCookie: false,
detectLngFromHeaders: true,
fallbackLng: ['en-GB', 'dev']
});
after-app.js
i18n.init({
resGetPath: path.join(__dirname, '../new-path.json')
}, function(t) {
// Here `t` does not get the strings in the new resGetPath
});
Can anybody tell me how to change resGetPath
on the fly, or tell me what I'm doing wrong?
Upvotes: 2
Views: 1219
Reputation: 10646
I figured it out.
You just have to run i18n.sync.resStore = {}
before you run init
, then it will force a reload.
Upvotes: 2