6

I'm trying to translate my website content. Everything worked fine expect the validation messages which come from mage/validation.js, and the minicart content translation is not showing on the frontend too.

4 Answers 4

1

You must override that file in your theme en app/design/frontend/VENDOR/THEME/web/mage/validation.js and your string for translate must be this away:

$.mage.__('Text to translate')
0

This is a Magento bug as of the current version 2.0.2. Magento asynchronously loads a JSON file for JavaScript translations. It can happen that some JavaScript widgets are loaded before the translation is loaded, those then are not translated. This often happens with the add to cart widget which loads quite fast.

There is a workaround for it but you need to change code in two places:

In /frontend/templates/product/list.phtml, change the block around line 140:

<script type="text/x-magento-init">
{    "[data-role=tocart-form], .form.map.checkout": {
       "catalogAddToCart": {
           "addToCartButtonTextDefault": "<?php echo __('Add to Cart'); ?>",
           "addToCartButtonTextWhileAdding": "<?php echo __('Adding...'); ?>",
           "addToCartButtonTextAdded": "<?php echo __('Added'); ?>"
       }
   }
}
</script>

In /frontend/templates/product/view/addtocart.phtml change the submitHandler around line 67:

       submitHandler: function (form) {
           var widget = $(form).catalogAddToCart({
               bindSubmit: false,
               "addToCartButtonTextDefault": "<?php echo __('Add to Cart'); ?>",
               "addToCartButtonTextWhileAdding": "<?php echo __('Adding...'); ?>",
               "addToCartButtonTextAdded": "<?php echo __('Added'); ?>"
           });

           widget.catalogAddToCart('submitForm', $(form));

           return false;
       }

If you encounter the same problem in other places, you can do it similarly.


Source: Splendit Internet who published a German language pack and found this issue.

0

It looks like JS translation issue. Quick solution could be just remove deployed js translation file.

In magento root run

find pub/static/frontend -name js-translation.json -exec rm -rf {} \;
0

The only method I have yet found that works consistently for translating all aspects of Magento 2 is through the creation of a language pack. This will work for both JavaScript Translations and hardcoded phrases wrapped in translation syntax.

Step 1) Create a CSV of translatable phrases, this is done via SSH Step 2) Take the CSV and create a Language pack based on the collected phrases in the CSV. Step 3) Install the language pack on the Magento 2 installation

Magento 2 develop documentation has a number of articles covering those steps.

You can also find a full article on how to complete all set of step by step instructions at Bullet Proof Translation & Localization of a Magento 2 Store

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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