Translation with arguments.
-
Just want to ask how do you deal with the following type of translations:
"tag": "Topics tagged under "%1"",
NodeBB/public/language/en@pirate/pages.json at c9f285a883104cb87802fae8c5d321dea8154680 路 NodeBB/NodeBB
Node.js based forum software built for the modern web - NodeBB/public/language/en@pirate/pages.json at c9f285a883104cb87802fae8c5d321dea8154680 路 NodeBB/NodeBB
GitHub (github.com)
I know they're supported on Nodebb, but i can not find an example of how the translator manage the arguments during translation, or the way they're processed after the translation itself (if the translator doesn't manage that itself).
I know it should be quite simple to find and example, but after checking the docs, the translator.js tests and a couple of plugins, i can not see how it is done
Just want to translate a string with arguments client side.
Thanks in advance.
-
Here is one, looks like it's just comment-separated values.
https://github.com/NodeBB/nodebb-theme-persona/blob/master/templates/register.tpl#L32In the client, use strings instead of the template variables.
require(['translator'], function(translator){ var foo = "FOO"; var bar = "BAR"; // v Dont put this space here. translator.translate('[[ register:help.username_restrictions, '+foo+', '+bar+']]', function(msg){ console.log(msg); // Output: "A unique username between FOO and BAR characters." }); });
-
Hi @yariplus
and if the foo variable has comma on its text? like :require(['translator'], function(translator){ var foo = "FOO, FOO2"; var bar = "BAR"; // v Dont put this space here. translator.translate('[[ register:help.username_restrictions, '+foo+', '+bar+']]', function(msg){ console.log(msg); // Output: "A unique username between FOO and FOO2 characters." }); });
How can I have the output "A unique username between FOO, FOO2 and BAR characters." ?
I have tried many things but no success.
Thanks for your help.
-
@marcelo-lopes escape the comma as an HTML entity:
text.replace(/,/g, ',')