i18Next - NodeJS - How to change translations without reloading server

不问归期 提交于 2020-01-14 19:30:48

问题


I am using i18next package for NodeJS to enable translation. I am using it as standard with a json file for each language-COUNTRY pair.

I'd like to build an admin page to edit translations without having to dig into the code; then, how can I "reload" the json files once edited by admin, without having to restart the server ?

Also, is it possible to use a DB (i am using mongodb) instead of JSON files ? Would it be more appropriate in this case?


回答1:


I wish i knew the answer to how to reload the JSON files without completely re-initializing i18next-node.

In terms of storing your translations in a database, i18next-node can connect to MongoDB (as well as Redis and CouchDB): http://i18next.com/node/pages/doc_init.html#backend




回答2:


You can set

i18next.sync.resStore = {}

and then call

i18next.init(callback)

to force a reload of your preloaded languages.




回答3:


It is better to use an official API of i18n with reloadResources.

// reload all
i18next.reloadResources();

// reload languages
i18next.reloadResources(['de', 'fr']);

// reload namespaces for all languages
i18next.reloadResources(null, ['ns1', 'ns2']);

// reload namespaces in languages
i18next.reloadResources(['de', 'fr'], ['ns1', 'ns2']);


来源:https://stackoverflow.com/questions/17213223/i18next-nodejs-how-to-change-translations-without-reloading-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!