Internationalization
We are using the i18next library for NLS support in both the runtime and editor.
Core Message Catalogs
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 |
Node Modules Catalogs
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>
.
Loading catalogs in the editor
All of this is subject to change - need to figure out how best for the editor to express what language it wants the catalogs in
A node's localized help will automatically get included with the existing methods to retrieve the node's editor configuration.
For message catalogs, a new api end-point is added:
/locales/__namespace__
For example:
/locales/node-red
will load the catalog for all core nodes.
/locales/node-red-contrib-twilio/twilio
will load the catalog for the node-red-contrib-twilio/twilio
node set.
Using i18n for messages
Runtime
A new module is provided, red/i18n
as a wrapper to the external i18next
module. In the majority of cases within the runtime, the messages are used within calls to log.log/warn/...
. As a convenience, log._()
is provided as a wrapper to the i18next.t
function.
var log = require("red/log.js");
// log._ is provided as a wrapper to i18next.t
// Retrieve the value of the message `runtime.version`
log.info(log._("runtime.version"));
// Retrieve the value of the message `example.insert" with a named insert
// "example.insert" : "I have a value of __myValue__"
log.info(log._("example.insert",{myValue: 123});
See the documentation for i18next.t
for more examples around plural handling etc.
Nodes
Nodes are passed a reference to the RED
object as part of the standard node module interface. Within that object, RED._()
can be used 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.
Editor
RED._()
is provided for core editor code.
Any html element can set a data-i18n
attribute, as documented here. NB: $(element).i18n()
must be called after element
is added to the DOM in order for these attributes to be parsed.
Nodes
As well as the data-i18n
attribute for html elements, all node definition functions (oneditprepare
etc) can use this._()
to retrieve messages, pre-scoped to the node's namespace.
Progress
Please update this table to indicate which files have been updated for i18n ("done"). Also, update to indicate which files you are planning to tackle so we don't duplicate effort.
File | Who/Progress |
---|---|
editor/js/comms.js | done |
editor/js/history.js | done |
editor/js/i18n.js | done |
editor/js/main.js | done |
editor/js/nodes.js | done |
editor/js/settings.js | done |
editor/js/ui/clipboard.js | done |
editor/js/ui/deploy.js | done |
editor/js/ui/editor.js | done |
editor/js/ui/keyboard.js | done |
editor/js/ui/library.js | done |
editor/js/ui/menu.js | done |
editor/js/ui/notifications.js | done |
editor/js/ui/palette.js | Allen |
editor/js/ui/sidebar.js | done |
editor/js/ui/state.js | done |
editor/js/ui/subflow.js | done |
editor/js/ui/tab-config.js | done |
editor/js/ui/tab-info.js | done |
editor/js/ui/tabs.js | done |
editor/js/ui/touch/radialMenu.js | done |
editor/js/ui/view.js | done |
editor/js/ui/workspaces.js | done |
editor/js/user.js | done |
editor/js/validators.js | done |
editor/templates/index.mst | done |
red.js | done |
red/api/auth/clients.js | done |
red/api/auth/index.js | done |
red/api/auth/permissions.js | done |
red/api/auth/strategies.js | Scott |
red/api/auth/tokens.js | done |
red/api/auth/users.js | done |
red/api/flows.js | done |
red/api/index.js | done |
red/api/info.js | done |
red/api/library.js | done |
red/api/nodes.js | done |
red/api/theme.js | done |
red/api/ui.js | done |
red/comms.js | done |
red/events.js | done |
red/i18n.js | done |
red/log.js | done |
red/nodes/credentials.js | done |
red/nodes/Flow.js | done |
red/nodes/flows.js | done |
red/nodes/index.js | done |
red/nodes/Node.js | done |
red/nodes/registry/index.js | done |
red/nodes/registry/loader.js | Scott |
red/nodes/registry/localfilesystem.js | done |
red/nodes/registry/registry.js | Scott |
red/red.js | Scott |
red/server.js | done |
red/settings.js | done |
red/storage/index.js | done |
red/storage/localfilesystem.js | done |
red/util.js | done |
nodes/core/analysis/72-sentiment.html | done |
nodes/core/analysis/72-sentiment.js | done |
nodes/core/core/20-inject.html | done |
nodes/core/core/20-inject.js | done |
nodes/core/core/25-catch.html | done |
nodes/core/core/25-catch.js | done |
nodes/core/core/33-link.html | |
nodes/core/core/33-link.js | |
nodes/core/core/58-debug.html | done |
nodes/core/core/58-debug.js | done |
nodes/core/core/75-exec.html | done |
nodes/core/core/75-exec.js | done |
nodes/core/core/80-function.html | done |
nodes/core/core/80-function.js | done |
nodes/core/core/80-template.html | done |
nodes/core/core/80-template.js | done |
nodes/core/core/89-delay.html | done |
nodes/core/core/89-delay.js | done |
nodes/core/core/89-trigger.html | done |
nodes/core/core/89-trigger.js | done |
nodes/core/core/90-comment.html | done |
nodes/core/core/90-comment.js | done |
nodes/core/core/98-unknown.html | done |
nodes/core/core/98-unknown.js | done |
nodes/core/hardware/35-arduino.html | done |
nodes/core/hardware/35-arduino.js | done |
nodes/core/hardware/36-rpi-gpio.html | done |
nodes/core/hardware/36-rpi-gpio.js | done |
nodes/core/io/10-mqtt.html | done |
nodes/core/io/10-mqtt.js | done |
nodes/core/io/21-httpin.html | done |
nodes/core/io/21-httpin.js | done |
nodes/core/io/22-websocket.html | done |
nodes/core/io/22-websocket.js | done |
nodes/core/io/23-watch.html | done |
nodes/core/io/23-watch.js | done |
nodes/core/io/25-serial.html | done |
nodes/core/io/25-serial.js | done |
nodes/core/io/31-tcpin.html | done |
nodes/core/io/31-tcpin.js | done |
nodes/core/io/32-udp.html | done |
nodes/core/io/32-udp.js | done |
nodes/core/io/lib/mqttConnectionPool.js | |
nodes/core/io/lib/mqtt.js | |
nodes/core/logic/10-switch.html | done |
nodes/core/logic/10-switch.js | done |
nodes/core/logic/15-change.html | done |
nodes/core/logic/15-change.js | done |
nodes/core/logic/16-range.html | done |
nodes/core/logic/16-range.js | done |
nodes/core/parsers/70-CSV.html | done |
nodes/core/parsers/70-CSV.js | done |
nodes/core/parsers/70-HTML.html | done |
nodes/core/parsers/70-HTML.js | done |
nodes/core/parsers/70-JSON.html | done |
nodes/core/parsers/70-JSON.js | done |
nodes/core/parsers/70-XML.html | done |
nodes/core/parsers/70-XML.js | done |
nodes/core/social/27-twitter.html | done |
nodes/core/social/27-twitter.js | done |
nodes/core/social/32-feedparse.html | done |
nodes/core/social/32-feedparse.js | done |
nodes/core/social/61-email.html | done |
nodes/core/social/61-email.js | done |
nodes/core/social/91-irc.html | done |
nodes/core/social/91-irc.js | done |
nodes/core/storage/28-tail.html | done |
nodes/core/storage/28-tail.js | done |
nodes/core/storage/50-file.html | done |
nodes/core/storage/50-file.js | done |
nodes/core/storage/65-redisout.html | done |
nodes/core/storage/65-redisout.js | done |
nodes/core/storage/66-mongodb.html | done |
nodes/core/storage/66-mongodb.js | done |
Language specific Topics
- Design: i18n-de (german)