Developer Question: polyglot keys in js
Can someone from UNA explain how I use language keys in JavaScript? There is absolutely no documentation at all.
Thank you ☺
-
-
·
LeonidS
- ·
Hello @Wise!
The rules of the lang keys translations for the JavaScript code is the same like for others. The only difference is the calling the addJsTranslation method of the BxDolTemplate class on the page where those lang keys will be used. For example the code of the Payment cart (modules/boonex/payment/classes/BxPaymentTemplate file):
$this->addJsTranslation(array('_bx_payment_err_nothing_selected'));
-
·
LeonidS
-
- · Wise
-
·
In reply to LeonidS
- ·
Greetings @LeonidS 👋
What if the JavaScript is preloaded, used site wide, for different blocks? Is there a way to also do it globally?
-
-
·
LeonidS
-
·
In reply to Wise
- ·
You may add the calling of the mentioned addJsTranslation to the sys_injections table. Just place there the service call of your code:
INSERT INTO `sys_injections`(`name`, `page_index`, `key`, `type`, `data`, `replace`, `active`) VALUES ('sys_head', 0, 'injection_body_class', 'service', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:18:"add_js_translation";s:6:"params";a:1:{i:0;s:10:"body_class";}s:5:"class";s:21:"TemplTemplateServices";}', 0, 1);
Smth like that. Be sure that you use your own module, this system part has been give as example.
-
·
LeonidS
-
- · Wise
- ·
I got it. Thank you @LeonidS
I do have a question. In my page source, I have the keys injection twice. It seems the system is doing it in two places. Since I am consolidating and trying to clean up all these modules injecting everything everywhere - how can I track where this double inject is from?