i18Next-NodeJS-如何在不重新加载服务器的情况下更改翻译 [英] i18Next - NodeJS - How to change translations without reloading server
问题描述
我正在使用NodeJS的i18next软件包来启用翻译.我将它与每个国家语言对的json文件作为标准文件一起使用.
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.
我想建立一个管理页面来编辑翻译,而不必深入研究代码;那么,如何在不经重新启动服务器的情况下重新加载"由admin编辑过的json文件呢?
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 ?
还可以使用数据库(我在使用mongodb)代替JSON文件吗?在这种情况下会更合适吗?
Also, is it possible to use a DB (i am using mongodb) instead of JSON files ? Would it be more appropriate in this case?
推荐答案
最好将i18n的官方API与 reloadResources .
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']);
这篇关于i18Next-NodeJS-如何在不重新加载服务器的情况下更改翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!