1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Updated Design: i18n (markdown)

Nick O'Leary 2015-05-08 16:42:12 +01:00
parent 6d46654a33
commit 110b748385

@ -60,19 +60,23 @@ will load the catalog for the `node-red-contrib-twilio/twilio` node set.
### Runtime
var i18n = require("./path/to/i18n.js");
// i18n._ is provided as a wrapper to i18next.t
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`
console.log(i18n._("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__"
console.log(i18n._("example.insert",{myValue: 123});
log.info(log._("example.insert",{myValue: 123});
See the documentation for `i18next.t` for more examples around plural handling etc.
#### Nodes
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.
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