0

I experience a problem on a Magento 2.4.1 store.

The problem: the Add to cart button on the product page is translated correctly on initial load. This is in Dutch in my case: "In Winkelwagen". After clicking the button it changes to untranslated text "Adding..." and then "Added" and finally it changes to "Add to Cart" so it resets from Dutch to English when using the add to cart button.

This only happens in production mode. In developer mode the several translations work as expected.

I did some research I found similar issues but those are dated.

Questions:

  • Is this a known bug for this version? (M2.4.1)
  • How can I fix it?
2
  • Just for info I tested a production 2.4.1 store with German language pack and did not see this behaviour. Text for add to cart when clicked remains in German. Does your language pack include all the required translations.
    – paj
    Apr 16, 2021 at 11:47
  • @paj Yes it does. I even looked up the js-translation.json file in the locale. And the translations are even in this file. So there is something wrong in the updating mechanism. Thanks for testing in 2.4.1. I didn't had the time to do that yet.
    – Akif
    Apr 16, 2021 at 11:51

1 Answer 1

0

I did not check the Magento issues that you commented, but I have experienced a lot of issues with translation on Javascript in the past (pub/static/frontend/Vendor/theme/en_US/js-translation.json)

You can first check that JSON file and try to identify if the translation for: 'Adding...' and 'Added' are present on the file (in your local will be a different language folder than en_US)

After that you can check the file that will render the text on the button:

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js#L199

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js#L211

You can debug those lines even on production mode and check why the mage/translate is not working well.

You can also resolve the issue creating a custom widget based on the validate-product that is trigger when you click over the 'Add To Cart' button

https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Catalog/view/frontend/web/js/validate-product.js#L36

I did some tests directly on the file, just for test purposes. Like:

submitHandler: function (form) {
                    var jqForm = $(form).catalogAddToCart({
                        bindSubmit: bindSubmit,
                        addToCartButtonTextWhileAdding: 'Toevoegen',
                        addToCartButtonTextAdded: 'Toegevoegd',
                        addToCartButtonTextDefault: 'In Winkelwagen'
                    });

                    jqForm.catalogAddToCart('submitForm', jqForm);

                    return false;
                }

It works well for me.

I do not speak Dutch, so please forgive my mistakes related to that :)

Good luck!

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.