-
Notifications
You must be signed in to change notification settings - Fork 0
Design: i18n
We are using the i18next library for NLS support in both the runtime and editor.
| Component | Namespace | Location |
|---|---|---|
| Runtime | runtime |
node-red/locales/__lang__/runtime.json |
| Editor | editor |
node-red/locales/__lang__/editor.json |
| Core nodes | node-red |
node-red/nodes/core/locales/__lang__/messages.json |
A node module provides message catalogs on a per-node-set basis. Given a node-set identified in package.json as:
"node-red": {
"myNode": "lib/my-node.js"
}
The following message catalogs may exist:
lib/locales/__lang__/my-node.json
lib/locales/__lang__/my-node.html
NB: the locales directory is relative to the node's .js file.
The .json file is the message catalog for both runtime and editor.
The .html file contains the localized node help content. The help content in the top-level .html file may identify what language it provides using a data-lang attribute: (en-US assumed if not set).
<script type="text/x-red" data-help-name="foo" data-lang="en-US">
<p>A foo node</p>
</script>
The catalog for a node-set is added under the namespace <module>/<set>.
A new api end-point is added to load message catalogs:
/locales/__lang__/__namespace__.json
var i18n = require("./path/to/i18n.js");
// i18n._ is provided as a wrapper to i18next.t
// Retrieve the value of the message `runtime.version`
console.log(i18n._("runtime.version"));
// Retrieve the value of the message `example.insert" with a named insert
// "example.insert" : "I have a value of __myValue__"
console.log(i18n._("example.insert",{myValue: 123});
Nodes can use RED._() to retrieve messages. The function they are provided is pre-scoped to the node's own namespace so they don't have to worry about providing it with each message.