asked in NodeJS by (430 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 (430 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 (940 points)
Try to create a global function to get the data, and return as array
commented by (430 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 (690 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 (430 points)
thanks for the reference :)
Forum Info Teknologi terkini dari para ahli industri Indonesia. Techmind membawa teknologi dunia, lebih dekat dengan masyarakat Indonesia. #beritateknologi.
...