1

This question already has an answer here:

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')?

marked as duplicate by Fabian Schmengler, Qaisar Satti, 7ochem, Amit Bera, brentwpeterson Oct 18 '16 at 20:40

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You can check with magento.stackexchange.com/questions/99966/… – Krishna ijjada Oct 17 '16 at 4:55
  • have you keep mage/translate in your js? – Rakesh Jesadiya Oct 17 '16 at 5:24
  • @fschmengler No duplication found in js-translation.json – Ricky.C Oct 18 '16 at 2:47
  • I had the same problem like "Cannot translate phases in $.mage.__('XXX')" when phrase in phtml worked perfect. So, the solution was ingeniously simple. $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 __('Translated phrase') . – Galina Apr 6 '18 at 13:56
1

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>

Not the answer you're looking for? Browse other questions tagged or ask your own question.