asked in NodeJS by (0 points)
edited by

How to make the array on i18n configuration option locales to be dynamic?

the existing code is :

const lang = require('i18n');
lang.configure({
locales: ["id", "en"],
defaultLocale: 'id',
cookie: 'lang',
directory: __dirname + '/locales'
});
app.use(lang.init);

i want the value of option locales will be fill with value from database.

Notes: 

this configuration is on app.js

3 Answers

answered by (0 points)
 
Best answer
untill now i have one solution for this case.

that is create a cronjob to restart app.js, and give a message that the new language will be available at the next day.

thanks for all of the answers :)
answered by (0 points)
Try to create a global function to get the data, and return as array
commented by (0 points)
currently, the array using data from database.
but the problem is implement it as new configuration.

because this configuration is implemented when app.js started or restarted.
answered by (0 points)
You can using dialect module for Node (https://github.com/masylum/dialect) as translation alternate, that module can get translation from DB (especially from MongoDB).
commented by (0 points)
thanks for the reference :)
...