nodeRed 源码分析4- i18n NLS (national language suppor) 多国语言支持

i18n NLS (national language suppor) 多国语言支持

所使用的库

  • i18next
  • https://www.i18next.com/

核心模块翻译数据

Component Namespace Location
Runtime runtime runtime/locales/__lang__/runtime.json
Editor editor editor-client/locales/__lang__/editor.json
Core nodes node-red nodes/nodes/core/locales/__lang__/messages.json

代码解析

默认 Lang

“en-US”

使用

  • i18n._(“xxx.xxx.xxx.xxx”);
  • log._(“xxx.xxx.xxx.xxx”);

主要方法

  • i18n.init(opt ,callback);
    完成初始化
  • i18next.loadNamespaces(ns, callback) // -> returns a Promise
    Loads additional namespaces not defined in init options.

实例

以node-red-node-rbe模块为例:

  1. 多国语言路径’d:\project\IOT_OpenSource\node-red-master\node_modules\node-red-node-rbe\locales’
  2. 多国语言信息文件
    rbe.json
  3. 多国语言帮助信息
    rbe.html
  4. 将模块按照规定的位置放置,即可启动i18n功能
  5. 代码中使用
    RED._(“rbe.warn.nonumber”) 即可按当前语言配置输出想要的结果

猜你喜欢

转载自blog.csdn.net/lxmuyu/article/details/113357817