Skip to content

Internationalisation (i18n) 🚧

Config files

sh
├── src
│   ├── locales # Global locales files
│   │   ├── en-US.json
│   │   └── fr.json
│   ├── nodes
│   │   ├── my-node-1
│   │   │   ├── locales # Node specific locales files
│   │   │   │   ├── en-US.json
│   │   │   │   └── fr.json

Global 👉 available in all nodes

Mandatory ⚠️

Place your global config files in the src/locales directory. Files must be named with the language code of Node-RED. For example, en-US.json.

For example, add a file src/locales/en-US.json with the following content:

json
{
  "hello": "Hello"
}

This will make the hello key available in all nodes.

Scoped 👉 available in a specific node

Mandatory ⚠️

Place your global config files in the src/nodes/my_node/locales directory. Files must be named with the language code of Node-RED. For example, en-US.json.

For example, add a file src/nodes/my_node/locales/en-US.json with the following content:

json
{
  "foo": "Foo"
}

This will make the foo key available only in the my_node node.

Usage

In pug files

By default, id is used to match with key in local's files.

jade
+dxpFormRowInputText({ id: 'name', label: 'Name', icon: 'tag' })

and you can set key in local file:

json
{
  "name": "my perfect name",
  "name-placeholder": "my perfect name" // key is automatically generated
}

Alternatively, you can pass an arbitrary i18n key:

jade
+dxpFormRowInputText({ id: 'name', label: 'Name', icon: 'tag', i18nKey: 'other_key' })
json
{
  "other_key": "my perfect name on other key",
  "other_key-placeholder": "my perfect name" // key is automatically generated
}

NB:

  • i18n key is apply on label inner text and title prop.
  • placeholder for inputText is also considered and a new key {key}-placeholder is automatically generated

In editor HTML

⚠️ Please, consider use pug file 🙏

You can follow official doc but with one important difference:

You don't need to prefix the key with the node name. Just use the key directly.

For example. In the file src/nodes/my_node/editor/index.html:

✅ Good

html
<span data-i18n="foo"></span>

❌ Bad

html
<span data-i18n="my_node.foo"></span>

WARNING

foo must be defined in the global or scoped node config files.

In scripts

For now, you can use the RED._ function to get the translation from Node-RED official doc.

So, you must include node name in the key.