12

I'm trying to translate some text in the checkout page:

"Provided Zip/Postal Code seems to be invalid."

However, when I add the following to frontend/..theme../Magento_Checkout/i18n/en_US.csv and re-deploy, the translation isn't there:

"Provided Zip/Postal Code seems to be invalid.","Test."

I cleared cache as well. What am I doing wrong?

2

6 Answers 6

25

Create a directory app/i18n/Vendorname/en_US

Issue command:

bin/magento i18n:collect-phrases --output "app/i18n/Vendorname/en_US/en_US.csv" --magento This will collect all the translatable phrases in csv file and place it in the specified path. Make changes to the csv file as per your requirement and when ready issue command:

bin/magento i18n:pack app/i18n/Vendorname/en_US/en_US.csv -d en_US

This will deploy the translations from your file.

clear the cache etc and you should see your changes.

9
  • This looks promising. It says the language package was saved successfully but the translation is still not there..
    – Cake
    Commented Oct 24, 2016 at 9:37
  • When I do the collect-phrases command again, the translation is back to what it was. Why isn't it saving?
    – Cake
    Commented Oct 24, 2016 at 9:40
  • That's normal behavior, when you recollect phrases it overrides your changes because Magento has recollected all default phrases. Process is you collect phrases, make your changes and deploy them, once deployed you can go in the concerned module let's say you made change for Add to Cart to Add to Bag, you can go to vendor/module-catalog/i18n/en_US.csv and look for your change. Just retested this and it works as it should. Make sure you're changing the second instance in translation and clearing the cache properly. You can also try deploying static content once again.
    – Devtype
    Commented Oct 24, 2016 at 9:52
  • Great thanks, it works indeed. However, some translations don't come through. The 'Example:' translation and 'Required fields' aren't translated. How come?
    – Cake
    Commented Oct 24, 2016 at 10:56
  • Found the problem. I had to php bin/magento setup:upgrade. After that my site was messed up, but then deplying the theme fixed it. No idea why this worked. Thanks
    – Cake
    Commented Oct 24, 2016 at 11:04
5

Had the same problem on my Magento 2 website, tried all sorts of suggestions how to fix it but the only thing that worked for me was -

  1. go to /pub/static/frontend/<theme>/<theme>/<language for example pl_PL>

  2. Find js-translation.json and delete it (make a copy of it just in case!)

  3. Go back to your magento root folder and run php bin/magento setup:static-content:deploy pl_PL

  4. Then run php bin/magento cache:flush

That's it. If you go back to /pub/static/frontend/<theme>/<theme>/<language for example pl_PL> folder, notice that js-translation.json have been generated again.

This problem happens because when you run static deploy, magento generates js-translation.json file with all your translations inserted into this one file and calls it in every time the page is loaded. So when it's already generated and usually empty, it cannot overwrite it with new information. By deleting it and regenerating it will solve the problem.

Hope this is going to help somebody.

2
  • Hi @Pinky_P, in my case the js-translation.json is updated with my expected translation. But it not showing in frontend. Could you please help me to resolve this issue.
    – Ramya
    Commented Mar 12, 2020 at 7:35
  • js-translation.json is not updating with the correct data from csv file
    – Manjunath
    Commented Jan 6, 2022 at 14:30
4

You can change only text which is written in translation

Like : $this->__("Sample Taxt");

Suggested text not written in translation so you can not change it with translation.

If you want to change it, you can find it in JS file which is located :

vendor/magento/module-checkout/view/frontend/web/js/model/shipping-rates-validator.js

Note : You have to override JS file to in your theme.

Delete pub/static/*

Run Command :

php bin/magento setup:static-content:deploy 

php bin/magento cache:clean

Delete browser cache.

4
  • I tried this and it didn't work for some reason.
    – Cake
    Commented Oct 24, 2016 at 8:51
  • I copied that file, changed the translation, and put it in app/design/frontend/<vendor>/<theme>/Magento_Checkout/web/js/model, re-deployed and cleaned cache. But no change..
    – Cake
    Commented Oct 24, 2016 at 9:30
  • check my updated answer. I hope now working for you. Commented Oct 24, 2016 at 9:37
  • This indeed worked. However, the solution provided by Devtype suits my needs more in this case. Thanks for the help! :)
    – Cake
    Commented Oct 24, 2016 at 11:05
1

Tried editing the following, but nothing worked:

app/i18n/vendor/module/en_US.csv
app/design/frontend/package/theme/i18n/en_US.csv
app/design/frontend/package/theme/web/js-translation.json
app/design/frontend/package/theme/web/js-translation-en_US.json

Later on, found this answer and it worked: https://magento.stackexchange.com/a/299697/1883

It says:

Core Module translations will not be overridden in custom theme so you need to place the new translations in your custom module folder. Create an empty module or use your existing module.

  • I created a new module (app/code/MyCompany/MyModule)
  • Created a new file i18n/en_US.csv inside the module (app/code/MyCompany/MyModule/i18n/en_US.csv)
  • Added necessary translation text in the csv file.
  • Enabled the module and the translation finally got reflected in the frontend.
0

🎗Just a reminder...

Magento stores some translation data in the browser storage.

You may have to clean browser storage items in addition to Magento internal caches.

enter image description here

0

Always you need to use like: <?php echo __('Word To Translate'); ?> to translate any words in magento.

After that you need to add translated words in your locale csv file which is located in app/locale/{lang_ISO}/Your_Module.csv

like app//locale/fr_FR/Mage_Catalog.csv.

Magento will automatically coinsider this translationat the frontend.

1
  • The question is tagged as Magento 2 but this is a Magento 1 solution
    – Jacques
    Commented Mar 13, 2023 at 9:18

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.