Place the translation into i18n folder of your module.
Note that you need not en_US.csv file (though Magento 2 core modules have it): it is enough to make a translation file for your target language.
Some Magento 2 core modules use another way to translate JavaScript strings:
they define / require the mage/translate library
and use it:
But I was unable to get it working: in my case the translation was called earlier than the transation dictionary has been loaded from the server. $.mage.__ works for me.
Hey there, I am currently still facing a translation problem. Everything in our mage2 installation translates well, except for anything created with JS/KO.
For example, I am trying to translate the words “Adding…”, “Added” and “Add to Cart” from the file
Now, in that file the translation is done via $t. This does not work for me. So I tried using $.mage.__ still no success.
I checked the js-translation.json file but it was empty []
Any ideas on that issue? Does your translations work?
The js-translation.json file is autogenerated. You should delete it and delete the cache, and the system will recheck your new interface strings and the dictionary used and will create a new js-translation.json file.
I tried that. Deleted the JSON File, flushed cache multiple times, reloaded, still the same. File is empty, no translatable Strings seemed to be fetched.
I also tried following steps:
Cache Storage should be flushed (basically var/cache and var/view_preprocessed folders should be cleared)
Static files should be redeployed (delete all folders inside pub/static and run bin/magento setup:static-content:deploy de_DE)
did not work.
For my translations I created a custom theme, following the official guide on [Frontend Developer Guide][1].
So I have all my translations in
The js-translation.json file is generated only if there is a language package for the current language.
So you should create a language package for the de_DE.
The js-translation.json file is generated correctly, it is also loaded on the frontend side and even stored in local storage. But it seems that at the mentioned location in catalog-add-to-cart.js the translations are not yet loaded, so $t always returns the original (English) string. This is clearly a bug, not something that we could fix in the language pack.