Accessing a property defined in languages (internationalization) from client-side JS
-
What I meant to say was.. consider that I want 10 translated strings, I am supposed to write this piece of code 10 times...
translator.translate('[[global:my_first]]', function (translated) { ... }); translator.translate('[[global:my_fsecond]]', function (translated) { ... });
And so on...
-
Right, and I'm asking why you are translating these strings yourself in the first place.
-
That's not what I'm asking. I'm asking why you want to do the parsing of the translations manually instead of using the automatic translation that NodeBB does.
-
Please provide the code where you use these translations. It depends on what you're doing.
-
require(['translator'], function (translator) { translator.translate('[[map:my_location]]', function (translated) { my_location = translated; }); }); .... marker = L.marker(initialLocation, { draggable: true, title: my_location, alt: my_location, riseOnHover: true }).addTo(map) .bindPopup(initialLocation.toString()).openPopup();
-
Ok so this is one of the rare cases where manually translating is your only option.
If you want to get a bunch of translations, I'd suggest using a filename besides
global.json
, maybe usemap.json
instead. Then, you can do this:require(['translator'], function (translator) { translator.getTranslations(translator.getLanguage(), 'map', function (translations) { translations.my_location === 'My Location'; }); });
Also, please use code blocks from now on. It works like this:
``` // code goes here ```
-
Use code block when you make a post with code in it