0

Is this a magento bug or is something I am doing it working

I had created my translation file in my module i18n. For testing purpose I just modified few text.

app/code/Vendor/Namespace/i18n/en_US.csv

"Do you want to remove the item from cart?","Just Remove?"
"Login","Sign In"

In My JS File I have this piece of code which I need to translate

        deleteItem: function (data) {
            var self = this;
            confirm({
                content: $t('Do you want to remove the item from cart?'),
                actions: {
                    confirm: function () {
                        alert('Done');
                    },
                    always: function (event) {
                        event.stopImmediatePropagation();
                    }
                }
            });

        },

But the translation for the code does not work. When I deploy static content it does not adds the translation in js-translation.json file.

Does any one have a workaround?

0

Please clear cache and check while cleaning cache it will flush translate cache as well. In Magento 2 there is mage/translate js library and that you can require in your js and use it like

$.mage.__("your text here");

You will get translated text.

| improve this answer | |
  • yes mage/translate has already been defined and I have tried clearing cache and re deploy static content. But my JS translation does not appears in pub/static/js-translation.json file. – Priyank Dec 28 '17 at 5:35
0

It may be due to Magento bug. In vendor/magento/module-translation/Model/Json/PreProcessor.php

$area = $this->areaList->getArea($areaCode);
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);

needs to be:

$area = $this->areaList->getArea($areaCode);
$area->load(\Magento\Framework\App\Area::PART_DESIGN);
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);

https://github.com/magento/magento2/issues/8508#issuecomment-279332346

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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