Hi all,
I'm trying to use translation with context on a node's status. Due to the fact that RED._('translate-text', context)
is getting evaluated in backend without information about the clients languages, the translate-text
is sent to the frontend for translation (like described in "creating-nodes" documentation).
Unfortunately, with this implementation, we lose the ability to pass context information. Would it be possible to adjust status object and this code to allow parsing translation context?
I would suggest something like this:
// node implementation
node.status({
fill: "green",
shape: "dot",
text: "node-red:common.status.connected",
translationContext: {
time: (new Date()).toLocaleTimeString()
},
});
// @node-red editor-client red.js
RED.comms.subscribe("status/#", function (topic, msg) {
var parts = topic.split("/");
var node = RED.nodes.node(parts[1]);
if (node) {
if (msg.hasOwnProperty("text") && msg.text !== null && /^[@a-zA-Z]/.test(msg.text)) {
// change here
msg.text = node._(msg.text.toString(), { ...msg.translationContext, defaultValue: msg.text.toString() });
}
node.status = msg;
node.dirtyStatus = true;
node.dirty = true;
RED.view.redrawStatus(node);
}
});
This solution would also solve an existing request.
Thanks in advance!