Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js-translation.json not picking up theme translations 2.1.3 / 2.1.4 #8508

Closed
tadhgbowe opened this issue Feb 10, 2017 · 63 comments
Closed

js-translation.json not picking up theme translations 2.1.3 / 2.1.4 #8508

tadhgbowe opened this issue Feb 10, 2017 · 63 comments
Labels
Component: Translation Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@tadhgbowe
Copy link

Hello. Apologies is reported before. I couldn't see it.

My theme translation file is not appearing in certain locations. For example the mini cart overlay and the cart is empty it says "You have no items in your shopping cart."

In my theme I have the translation "You have no items in your shopping basket.". When I go to the cart page I can see underneath the main content title "You have no items in your shopping basket.". So I know it's working. However when I hover over the mini cart in the header the overlay continues to say "You have no items in your shopping cart."

Tried on 2.1.3 and 2.1.4 community edition.

I have tried a static deploy, deleted the js-translation.json file itself. No joy.

Question: Does the js-translation.json not pick up theme translations?

Preconditions

Locale set to en_GB - English (United Kingdom)
Create a new theme. Enable this in the backend via Content > Design - Configuration.
Create a i18n/en_GB.csv file with the above translation:
"You have no items in your shopping cart.","You have no items in your shopping basket."
Refresh block, page and translation caches.

Steps to reproduce

Go to cart page /onepage/cart. In the main content area underneath Shopping Cart I can see my translation "You have no items in your shopping basket.". However the mini-cart overlay doesn't display the new translation.

Expected result

The empty mini-cart overlay should translate to "You have no items in your shopping basket."

Actual result

The empty mini-cart overlay continues to display the core translation "You have no items in your shopping cart."

OTHER NOTES/OBSERVATIONS/TESTS:

  • If I create a language pack it does work! Curious. So why does it not pick up theme translations? This could be a bug I guess?

Thanks
T

@tadhgbowe
Copy link
Author

Update on this (spent all day debugging):

  • When you clear the translation cache and remove the js-translation.json file from your theme in pub/static/frontend/Magento/[your theme]/[your locale]/js-translation.json it will try to rebuild.

  • vendor/magento/framework/Translate.php is where all the main work occurs.

  • What I've found is when it starts to rebuild the js-translation.json (which starts from
    vendor/magento/module-translation/Model/Json/PreProcessor.php) it comes to vendor/magento/framework/Translate.php and it's not able to evaluate the theme for the config setting:

$this->_config['theme'] = $this->_viewDesign->getDesignTheme()->getId(); returns null.

So in the function _loadThemeTranslation() it fails because $this->_config['theme'] is not set (it's null). It should be returning the theme Id (in my case ID 4).

So there's something the matter with
\Magento\Framework\View\DesignInterface $viewDesign in the constructor.

Hope this helps. Is there a quick workaround I wonder?

Thanks
Tadhg

@thomvanderboon
Copy link

Duplicate of #8459

Thom

@Flamestyle
Copy link

Hello! Please write your steps and commands for two methods: create language pack and create theme translations.

@tadhgbowe
Copy link
Author

tadhgbowe commented Feb 12, 2017

Hello.
Thanks for the feedback. I did see #8459 and #7862 but this issue I believe is an additional problem.

I have also experienced the js-translation.json not building itself properly. Deleting the file does rebuild it but still fails to pick up theme translations (not 100% sure a "bin/magento setup:static-content:deploy..." works on my custom theme).

I have no idea what is meant by "Please write your steps and commands for two methods: create language pack and create theme translations".

I have noticed some quite short and disrespectful comments on GitHub. I can appreciate people's frustration but that isn't going to solve anything. I've given up valuable company time to try highlight this particular problem.

I haven't tested in versions previous to 2.1.3. I will try do this tomorrow.

Thanks
T :-)

@Flamestyle
Copy link

Flamestyle commented Feb 12, 2017

I see the same problem, but all commands are executed too different. So I asked to write all the steps that you did when deploying the language.
I try 2 methods:
Method 1: Create a language package same official docs, create 4 files: composer.json, language.hml, registration.php, ru_RU.csv.
After make this commands:

cd /var/www/html
rm -rf pub/static/*
rm -rf var/view_preprocessed/*
php /var/www/html/bin/magento cache:clean
bin/magento setup:static-content:deploy --theme Magento/backend en_US
bin/magento setup:static-content:deploy --theme Agestor/default ru_RU
php /var/www/html/bin/magento cache:clean

Method 2: Add file ru_RU.csv to my theme. Path: app/design/frontend/Agestor/default/i18n/.
After make this commands:

cd /var/www/html
rm -rf pub/static/*
rm -rf var/view_preprocessed/*
php /var/www/html/bin/magento cache:clean
bin/magento setup:static-content:deploy --theme Magento/backend en_US
bin/magento setup:static-content:deploy --theme Agestor/default ru_RU
php /var/www/html/bin/magento cache:clean

Right?

Two methods same official documentation. Don't works... js-translation.json - empty...
Thanks!

@tadhgbowe
Copy link
Author

tadhgbowe commented Feb 13, 2017

Hi Flamestyle / All.

You look to be doing everything correctly. I'm assuming you've set your Locale (In Stores > Configuration > General - Locale) to ru_RU?

However in my case the language pack is being picked up and the js-translation.json is not empty.

My Locale is set to en_GB. The code in my language.xml is set to en_GB.

It's the Theme translations that I want to pick up in my js-translation.json i.e.
app/design/frontend/<your_vendor_name>/<your_theme_name>/i18n/en_GB.csv

AND I THINK I'VE FOUND THE PROBLEM TO MY ISSUE:

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);

It needs to load the design before loading the translations. The above insertion then works for me! So hopefully Magento will pick up on this soon.

When you look at how other areas are loaded for example:
vendor/magento/framework/View/DesignLoader.php

You'll see:

$area = $this->_areaList->getArea($this->appState->getAreaCode());
$area->load(\Magento\Framework\App\Area::PART_DESIGN);
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);

The design must be present before the translations are loaded.

Thanks
Tadhg

@Flamestyle
Copy link

@tadhgbowe, yes General - Locale include ru_RU.
I have one question: you use method 1 or 2? I see you use file en_GB.csv app/design/frontend/[THEME]/default/i18n/en_GB.csv, but you write more about language.xml. So you use 2 methods together?
Thank you!

@tadhgbowe
Copy link
Author

Hello again,

I only created the language pack to see if my js-translation.json could pick up the translations from there. And yes that worked. But I never wanted to create a language pack. I simply wanted to be able to handle everything from my theme.

So in my example I can now remove the language pack. I only used it to prove that js translations worked when in a language pack and not from my theme.

My theme code (in database table theme) is called Training/default. If I run all the following commands it works fine:

rm -rf pub/static/*
rm -rf var/view_preprocessed/*
php /var/www/html/bin/magento cache:clean
bin/magento setup:static-content:deploy --theme Training/default en_GB

Please Note: When you setup a theme you can't just have an i18n folder and nothing else. The static-content:deploy will error saying that the Theme doesn't exist. You have to have some wee/css/source files in there for it to deploy for you.

Thanks
Tadhg

@Flamestyle
Copy link

Flamestyle commented Feb 14, 2017

Hello, @tadhgbowe! For me prefer to be able to handle everything from my theme too.
Your solution $area->load(\Magento\Framework\App\Area::PART_DESIGN); works!
Thank you so much!

@tadhgbowe
Copy link
Author

tadhgbowe commented Feb 14, 2017

Hi @Flamestyle and all others who read this.

Obviously this is a small Magento bug and hopefully they will pick up on this soon.

We can't change the core file vendor/magento/module-translation/Model/Json/PreProcessor.php for obvious reasons. For a workaround you can consider using a before Plugin, a Preference or as you'll see below the PreProcessor is already a part of the module-translation di.xml.

In your code/[Vendor]/[Module Name]/etc/di.xml you can use:

  1. Preference:

<preference for="Magento\Translation\Model\Json\PreProcessor" type="[Vendor]/[Module Name]\Model\Json\PreProcessor"/>

  1. before Plugin (preferred choice):

<type name="Magento\Translation\Model\Json\PreProcessor"> <plugin name="pluginTranslationJsonExtra" type="[Vendor]/[Module Name]\Plugin\Json\PreProcessor" sortOrder="10" disabled="false"/> </type>

  1. intercept existing module-translation di.xml AssetPreProcessorPool:

<virtualType name="AssetPreProcessorPool"> <arguments> <argument name="preprocessors" xsi:type="array"> <item name="json" xsi:type="array"> <item name="json_generation" xsi:type="array"> <item name="class" xsi:type="string">[Vendor]/[Module Name]\Model\Json\PreProcessor</item> </item> </item> </argument> </arguments> </virtualType>

All the best,
Tadhg

@carfantasy
Copy link

I have the same problem. But this fix doesn't work for me....

@Flamestyle
Copy link

Flamestyle commented Feb 21, 2017

@carfantasy Which of the two? Write all your steps so that can analyze.

@carfantasy
Copy link

Hi,
This is my issue and also the minicart issue:
#8337

I did:
composer update
php bin/magento setup:upgrade
php bin/magento cache:clean
php bin/magento setup:di:compile
rm -rf pub/static/*
rm -rf var/view_preprocessed/*
php /var/www/html/bin/magento cache:clean
bin/magento setup:static-content:deploy --theme Magento/backend en_US
bin/magento setup:static-content:deploy --theme (theme)/default nl_NL
php /var/www/html/bin/magento cache:clean

this was not the solution, so I did:

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);

rm -rf pub/static/*
rm -rf var/view_preprocessed/*
php /var/www/html/bin/magento cache:clean
bin/magento setup:static-content:deploy --theme Magento/backend en_US
bin/magento setup:static-content:deploy --theme (theme)/default nl_NL
php /var/www/html/bin/magento cache:clean

Still not the solution....

@tadhgbowe
Copy link
Author

Hi @carfantasy,

First you need to check that your Stores > Configuration > General > Locale Options : the Locale for you needs to be set to Dutch (Netherlands).

Secondly you need to make sure that your theme has the correct i18n/nl_NL.csv file. So it should live in a folder like app/design/frontend/[Theme/Vendor namespace]/[Theme e.g. default]/i18n

With all the caches enabled you should only need to refresh the translations cache. You can also simply delete the js-translation.json in your pub/static/frontend/[Theme/Vendor namespace]/[Theme]/nl_NL folder.

When the page loads (for example the basket page), there should be a call to build the js-translation.json.

If it's not generating a js-translation.json at all then I would stick on some debug in vendor/magento/module-translation/Model/Json/PreProcessor.php process function. It should go in here. If it isn't then that's another Magento bug. I've never had a problem it not entering this piece of code.

Please Note: If you have a language pack installed those translations will win over any theme and module translation phrases.
If you have any inline translations (DB table translation) these will win over all language pack, theme and module phrases.

My fix was specifically targeted at theme i18n folder translations e.g. [Theme]/i18n/en_GB.csv.

Thanks
Tadhg

@carfantasy
Copy link

Hi @tadhgbowe

I did all things you mentioned. When I do Stores > Configuration > General > Locale Options : the Locale for you needs to be set to Dutch (Netherlands). The Java script at the backend crashed. When I put it back in en_US the Java workts but there is missing tekst, My admin login is also set to en_US and still tekst is missing.

I will try do delete the theme files and run setup again. Than set to blank theme. Maybe this solves the issue...

@tadhgbowe
Copy link
Author

Hi @carfantasy,

If your javascript is crashing that definitely sounds bad. It might be worth trying it out on a brand new install of Magento. I've been used CE 2.1.4. I hope you get it working.

Kind regards,
Tadhg

@tadhgbowe
Copy link
Author

Hi @carfantasy and anybody else tuning in.

I think it's worth noting that when you make translation changes that require a js-translation.json rebuild, to test that the changes have come through okay:

  1. Delete the existing js-translation.json file in pub/static...
  2. Refresh the Translations cache
  3. Refresh your web page twice! The first time around it kicks off the js-translation.json file rebuild. It's only on the second page refresh will you see the contents of that newly generated json file.

Happy coding (if there's such a thing) :-)
Tadhg

@marcosdsdba
Copy link

marcosdsdba commented Apr 13, 2017

I've tested and problem persists also in Version 2.1.6

I found the problem mostly in Checkout

@daveyx
Copy link

daveyx commented May 16, 2017

here too in 2.1.6

@vherasymenko
Copy link

vherasymenko commented May 30, 2017

Hi. I Try reproduce this bug. (Maybe i use incorrect steps, if yes please correct me)

My steps for reproduce:

  1. Install magento
  2. Go to Admin side click "Store > Configuration"
  3. And change local on English(United Kingdom)
  4. Click "Save"
  5. Create custom them and apply it in "Content > Design"
  6. Go to folder with created theme and open foled i18n
  7. Add new file en_GB.csv
  8. In this file enter "You have no items in your shopping cart.","You have no items in your shopping test message."
  9. run next commands rm -rf pub/static/* && rm -rf var/view_preprocessed/* && php bin/magento cache:clean
  10. Go to storefront side "http://localhost/checkout/cart/ and verify displayed text

AR: Displayed "You have no items in your shopping test message.

3

Note: It`s correct behaviour for this case.

@tadhgbowe
Copy link
Author

tadhgbowe commented May 30, 2017

Hi K7Triton,

Thanks for the message. That's not the correct area I was talking about. I was focusing on the min-cart overlay in the header of the page. When you click on the basket icon (beside the search bar) you get a little overlay to say "You have no items in your shopping cart.".

The area you mention is built from a .pthml template file. They work fine. It's the .html knockout generated translations that get stuck :-)

screen shot 2017-05-30 at 14 46 00

@vherasymenko
Copy link

@tadhgbowe I reproduce this bug.
Thanks for your report.
Internal ticket MAGETWO-69601 was created for this issue.

@tadhgbowe
Copy link
Author

Hi @k7triton.

Great! The fix is below. Sorry I don't have time to follow up myself. What would be even more amazing is to be able to track MAGETWO-69601 somewhere. When the ticket has been resolved it would be great if the original source (i.e. here) could be updated with the Magento release versions that contained the fix. For people who stumble across this post in the future they can then clearly see what version it was fixed in. Right now it's quite fuzzy. Cheers. T

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);

It needs to load the design before loading the translations. The above insertion then works for me! So hopefully Magento will pick up on this soon.

@Elodie31
Copy link

Elodie31 commented Jun 1, 2017

Brilliant!!! I had issue with all translation in the mini-cart and @tadhgbowe fix is working perfectly. Now all my translation added to my theme are working!

@KrystynaKabannyk KrystynaKabannyk added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development and removed Progress: needs update labels Jun 1, 2017
@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Dec 18, 2017
@umarch06 umarch06 reopened this May 16, 2018
@umarch06
Copy link
Member

For me this issue still exists on Magento 2.2.2 production mode, I am using Valet+ on MacOSX.
I changed production mode to developer mode and the issue was fixed. Issue happens on checkout and admin pages. On admin pages, if I open a page which has grid in it, the error is there and due to which grid data is not loaded, but for other pages error happens but page loads normally.

Tried to fix it as suggested by @Tomasz-Silpion but issue cannot be resolved.

@robmacecs
Copy link

Still same issue in 2.2.3, not tested >=2.2.4 yet
@tadhgbowe 's fix doesn't seem to work on later versions

js-translation.json still just contains []

@Yonn-Trimoreau
Copy link

In Magento 2.2.5, Json/PreProcessor.php file does not contain the fix anymore.

And I manually added the fix to it, followed all the steps for clearing cache in pub/static, var/view_preprocessed.. Still does not work.

Theme translations are still not added to js-translation.json file.

I can't explain why the fix went away on 2.2.5 branch... How is this even possible ?

@magento-engcom-team magento-engcom-team removed the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Jul 29, 2018
@vivekaris
Copy link

i also followed all step but problem still in Magento 2.2.5

@barbazul
Copy link
Contributor

For all of you still struggling with this issue (like myself) here is the fix proposed in module format:

https://github.com/SemExpert/SemExpert_TranslationsFix

@ghost ghost self-assigned this Jan 3, 2019
@magento-engcom-team
Copy link
Contributor

magento-engcom-team commented Jan 3, 2019

Hi @engcom-backlog-tomash. Thank you for working on this issue.
Looks like this issue is already verified and confirmed. But if your want to validate it one more time, please, go though the following instruction:

  • 1. Add/Edit Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 2. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 3. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 4. If the issue is not relevant or is not reproducible any more, feel free to close it.

@ghost ghost removed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report labels Jan 3, 2019
@ghost ghost assigned ghost and unassigned ghost Jan 9, 2019
@magento-engcom-team
Copy link
Contributor

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • 6. Add label Issue: Confirmed once verification is complete.

  • 7. Make sure that automatic system confirms that report has been added to the backlog.

@ghost
Copy link

ghost commented Jan 16, 2019

Hi @tadhgbowe Thank you for your report.
The issue has been fixed in #16892 by @mage2pratik in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@ghost ghost closed this as completed Jan 16, 2019
@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Feb 22, 2019

Appears to be missing in 2.3.0
Had to add it in.

image

@araujoantonio
Copy link

I'm on Magento 2.3.5 and I have this issue.

The solutions presented do not help 😢

@adeptofvoltron
Copy link
Contributor

Still facing the issue on magento 2.3.5

@simonrl
Copy link

simonrl commented Aug 4, 2020

Same here for 2.3.4.
What's the reason this issue was closed?
Many people still report this bug.

@hostep
Copy link
Contributor

hostep commented Aug 4, 2020

Folks, this issue was closed because the original reported issue was fixed in Magento 2.2.2: #8508 (comment)

If you still run against this issue (or maybe a very similar one) please open a new ticket with exact steps of how to reproduce on a clean Magento installation. Doing it this way will get you quicker help then complaining on a 3-year old ticket.

Thanks! 🙂

@amenk
Copy link
Contributor

amenk commented Jun 15, 2021

We still have a problem in 2.3.5, that the translation "items" is not picked up and so not included into the js-translation.json
vendor/magento/module-checkout/view/frontend/templates/cart/minicart.phtml:20

            <!-- ko i18n: 'items' --><!-- /ko -->

Problem seems to be at least in that version *.phtml files are not scanned for JS translations. Not sure how it is with 2.4.2

As a workaround, one can createa file such as

app/design/frontend/Example/themename/Magento_Theme/web/template/additional-js-translations.html

and add all the missing translationed strings :-(

            <!-- ko i18n: 'items' --><!-- /ko -->

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Translation Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests