Translation added to i18n files, phrases in <?php echo __("XXX");?>can be translated, but the those in $.mage.__('XXX') cannot be translated.
Any work around to translate phrases in $.mage.__('XXX')?
Translation added to i18n files, phrases in <?php echo __("XXX");?>can be translated, but the those in $.mage.__('XXX') cannot be translated.
Any work around to translate phrases in $.mage.__('XXX')?
Let me answer the question myself:
Adding the code below to phtml file:
<?php
$_data = array(
'Are you sure you would like to remove this item from the shopping cart?' => __('Are you sure you would like to remove this item from the shopping cart?'),
);
?>
<script type="text/javascript">
require(["jquery", "mage/translate"],
function ($) {
$.mage.translate.add(<?php echo Zend_Json::encode($_data) ?>)
});
</script>
$t(...) and $.mage analizes only files *.js
Consequently it does not fall into the js-translation dictionary.
So when rendering a section script in phtml files, you should directly insert the already translated phrases with wrappers
– Galina Apr 06 '18 at 13:56__('Translated phrase').