Magento2: js-translation.json files are not removed/clear when performing a cache:clear or cache:flush

Created on 1 Mar 2017  路  5Comments  路  Source: magento/magento2


Preconditions


  1. Magento version 2.1.4
  2. PHP 7.x
  3. MySQL 5.6

Steps to reproduce

  1. Go to the checkout page after cart page to make the js-translation.json file cache.
  2. Set a new translation for "Review & Payments" within checkout. My example would be adding "Review & Payments","Overzicht & Betalen","module","Magento_Checkout" within app/i18n/VENDOR/language-nl_nl/nl_NL.csv
  3. Run php bin/magento cache:clean and/or php bin/magento cache:flush
  4. Reload checkout page, translation is not shown as the js-translation.json have not be cleaned/removed.

Expected result

  1. When clearing the cache js-translation.json should be cleaned/removed so upon next page reload new translation is shown.

Actual result

  1. After clearing cache and reloading checkout page the translation has not happened.

The only way I could force this to happen is by doing php bin/magento setup:upgrade as part of this is that it runs the following:
File system cleanup: /pub/static/frontend /var/view_preprocessed/frontools /var/view_preprocessed/source
However this seems to me to be overkill to have to run a setup:upgrade to clear out translations stored for Javascript.

Most helpful comment

Thanks @hostep and @thomvanderboon for your time in replying.

@thomvanderboon I did do a static content deploy however didn't seem to work but as you say maybe I didnt do a reload twice.

It just feels a little odd that a cache:flush translate doesn't clear all translations. I would say some better documentation is needed here to confirm this.

Then as a suggestion perhaps putting into the bin/magento CLI we could add under i18n something like i18n:cache:flush. This would do both the standard magento cache:flush translate and also the removing of the js-translation.json files.

Is this a good idea that you both would support?

All 5 comments

I understand the reasoning behind your request, since the caching in Magento caches non-js translations.

But, and this is a big but, flushing the cache should only clear Magento caches and shouldn't manipulate actual files.
This would be a disaster in a production environment, if Magento would try to remove the js translation files every time you flush the Magento cache.
On production environments, there could be a file permission policy active, where php isn't able to delete or create files in the pub/static directory for example.

So in my opinion, this is a very bad idea.
I'd suggest you simple remove the js translation files by hand every time you want it to be rebuilt on your development environment. Or even better, you can write your own custom script, maybe using grunt or gulp or something else, which does this by executing a simple command, it can probably be as simple as (not actually tested):

$ php bin/magento cache:flush translate && find pub/static/frontend -name 'js-translation.json' -delete

There are currently several issues with the js-translation.json file. The js-translation.json is part of the translation files and is preferably generated by regenerating the static content for a certain language. You do not need to rerun the setup:upgrade command.

Please take a look here: https://github.com/magento/magento2/issues/2951#issuecomment-276552659

Please note you will have to reload the page twice to have the correct js-translation.json loaded.

Thanks @hostep and @thomvanderboon for your time in replying.

@thomvanderboon I did do a static content deploy however didn't seem to work but as you say maybe I didnt do a reload twice.

It just feels a little odd that a cache:flush translate doesn't clear all translations. I would say some better documentation is needed here to confirm this.

Then as a suggestion perhaps putting into the bin/magento CLI we could add under i18n something like i18n:cache:flush. This would do both the standard magento cache:flush translate and also the removing of the js-translation.json files.

Is this a good idea that you both would support?

There are many translation related bug in Magento 2.x. Before supporting a new feature, I would much more like these bugs fixed.

I created a script to do the job. This works good enough for me.

Thom

Perhaps just go down the documentation route then on the magento 2 website then. Thanks for now.

Was this page helpful?
0 / 5 - 0 ratings