Hi,
I use RED._("node.myKey") but the result is below.
key 'node.myKey (en-US)' returned an object instead of string.
How can I get object from RED._() function? Because I want to get object from "Internationalisation" json file.
Hi,
I use RED._("node.myKey") but the result is below.
key 'node.myKey (en-US)' returned an object instead of string.
How can I get object from RED._() function? Because I want to get object from "Internationalisation" json file.
We do not support returning objects - only string messages.
Can I ask what your use case is for getting an object back?
Thank you so much for your reply.
My use case is using Internationalisation for display group of labels in external client javascript module.
I create httpAdmin.get at created-node.js for return Internationalisation string, which I want to use.
I create $.getJSON(..) function for get Internationalisation string from above (1).
After I got Internationalisation string, I send them to external client javascript module.
No problem, if it is impossible to get object.
At above (1), I maybe read each string intead of once reading object, then create a custom object from reading each string.
You should not need to create your own admin end-point; the editor will have loaded your node's message catalogue as well.
In my understand, the editor use Internationalisation through i18n in html tag.
I am not sure, is there another method for using Internationalisation through javascript or jQuery in html? Because I want to gather Internationalisation, and send to my external javascript module.
Below are my present code.
RED.httpAdmin.get('/emojiLabels', function(req, res) {
res.json({
"smile-people": RED._("node-line-notify.emoji-group-labels.smile-people"),
"animal-nature": RED._("node-line-notify.emoji-group-labels.animal-nature"),
"food-drink": RED._("node-line-notify.emoji-group-labels.food-drink"),
"activity": RED._("node-line-notify.emoji-group-labels.activity"),
"travel-places": RED._("node-line-notify.emoji-group-labels.travel-places"),
"objects": RED._("node-line-notify.emoji-group-labels.objects"),
"symbols": RED._("node-line-notify.emoji-group-labels.symbols"),
"flags": RED._("node-line-notify.emoji-group-labels.flags")
});
});
<script src="resources/node-red-contrib-node-line-api/emoji-picker.js"></script>
<script type="text/javascript">
(() => {
....
let objEmojiLabel = null;
$.getJSON('emojiLabels', (data) => {
console.log("success load emoji labels");
objEmojiLabel = data;
})
.fail(function () {
console.log("error load emoji labels");
})
.always(function () {
console.log("complete load emoji labels");
new EmojiPicker({
trigger: [
{
selector: '.btnEmoji',
insertInto: '.node-input-message'
}
]
}, setButtonState, objEmojiLabel);
});
.....
}
</script>
Please advise me.
If you are running in the editor, you have RED._()
function available to you.
You could try it straight away by opening the browser's JavaScript console with Node-RED editor open, then see what the following returns:
RED._("node-red-contrib-node-line-api/node-line-notify:node-line-notify.emoji-group-labels.smile-people")
Note how you have to prefix the message identifier with the catalog name - which is the module/set
identifier - where set
is the name of the entry in your package.json
that points to the node that loads this catalog...
This is based on what I can see in your current github.
Thank you very much for your advise.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.