Question on internationalisation: Can I have 1 json file for several nodes?

Hi, I've a question as I start to prepare uibuilder to use l8n internationalisation rather than fixed text strings.

As in the title - is it possible to define a single locale json file in my Node package that can be used across all of the nodes and their library modules?

The uibuilder node, in particular, uses a sub-folder of library modules, each of which is a class. I do pass the RED object to the library module classes so I can access RED._ but I would like to define common strings across all nodes and modules.

Thanks. J.

It is sort of possible, but not as elegant as perhaps you'd like.

A bit of terminology to help explain, apols if I'm telling you stuff you know, but for future readers of this thread....

In your package.json file, you have this:

  "node-red": {
    "version": ">=3",
    "nodes": {
      "uibuilder": "nodes/uibuilder.js",
      "uib-cache": "nodes/uib-cache.js",
      "uib-element": "nodes/uib-element/customNode.js",
      "uib-update": "nodes/uib-update/customNode.js",
      "uib-sender": "nodes/uib-sender.js",
      "uib-list": "nodes/uib-list/customNode.js"

The keys of the nodes property are internally known as the node-set name. Each node-set can have its own message catalog.

There is no concept of a module-wide catalog, but you can look-up messages from any other catalog that node-red has loaded. You do that by prefixing the message identifier with the catalog name.

For example, you could put all your common messages in uibuilder.json and then any other node would be able to use RED._("node-red-contrib-uibuilder/uibuilder:the.message.identifier")

It is a bit long winded to have to fully specify the catalog as well as the message id, but that's how you do it.

1 Like

Thanks Nick. That helps.

What about the library modules (in nodes/libs) - I assume that I'll have to specify the full name there?

It depends where they got their handle to the RED object from. If it was "nodes/uibuilder.js", then I think they will implicitly use the uibuilder catalog (unless they specify a different catalog name).

OK, I'll give that a test. They do get the RED object from the uibuilder node so that should be OK. It is simply passed by reference so that it is available wherever needed.

Thanks again. A day off so making a start on the next release :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.