magento2: Magento 2.2.0: Translations for 'Item in Cart' missing in mini cart.
Since updating one of our stores to Magento 2.2 the translations for ‘Item in Cart’ are not compiled into the var/view_processed/pub/static/frontend/{Magento-Theme}/{language code}/js-translation.json files, though the translations for ‘Items in Cart’ are correctly loaded.
Preconditions
- Magento 2.2.0
- PHP 7.0 and 7.1 (different local setups and different testservers)
- MySQL 5.5.5-10.1.23-MariaDB
Steps to reproduce
- Have a store view in another language than en_US.
- Set a translation for ‘Item in Cart’ for that language.
- Open your store with the store view according to language, where you expect the translation to be done.
- Add exactly one item to your cart.
- Open the mini cart.
Expected result
- ‘Item to Cart’ translated to store view given language.
Actual result
- ‘Item to Cart’ is not translated.
Details
So the problem or at least a symptom of the problem seems to be in the ‘vendor/magento/module-checkout/view/frontend/web/template/minicart/content.html’ template. Strangely not all ‘translate’-nodes are triggering the Magento 2 Content Compiler to actually set the requested translations into the theme and language given js-translations.json files.
Though the lines
33 - <translate args="'Item in Cart'" if="getCartLineItemsCount() === 1"/>
and
34 - <translate args="'Items in Cart'" if="getCartLineItemsCount() > 1"/>
are almost completely identical, the translations for ‘Items in Cart’ are loaded, but not for ‘Item in Cart’.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 22 (9 by maintainers)
Commits related to this issue
- Fix proposal for https://github.com/magento/magento2/issues/12081 — committed to mattijv/magento2 by mattijv 6 years ago
- MAGETWO-87575: Fix for #12081: missing translations in the js-translations.json #13528 - Merge Pull Request magento/magento2#13528 from mattijv/magento2:2.2-develop - Merged commits: 1. 9c35c459... — committed to magento/magento2 by deleted user 6 years ago
- MAGETWO-87575: Fix for #12081: missing translations in the js-translations.json #13528 — committed to magento/magento2 by deleted user 6 years ago
- Fix proposal for https://github.com/magento/magento2/issues/12081 — committed to sanganinamrata/magento2 by mattijv 6 years ago
- Fix proposal for https://github.com/magento/magento2/issues/12081 — committed to sanganinamrata/magento2 by mattijv 6 years ago
- Merge pull request #14 from sanganinamrata/2.1-develop-PR-port-13528 [Backport] Fix for #12081: missing translations in the js-translations.json — committed to sanganinamrata/magento2 by sanganinamrata 6 years ago
- ENGCOM-2292: [Backport] Fix for #12081: missing translations in the js-translations.json #16720 - Merge Pull Request magento/magento2#16720 from sanganinamrata/magento2:2.1-develop-PR-port-13528 - ... — committed to magento/magento2 by magento-engcom-team 6 years ago
- ENGCOM-2292: [Backport] Fix for #12081: missing translations in the js-translations.json #16720 — committed to magento/magento2 by VladimirZaets 6 years ago
- ENGCOM-2400: [Forwardport] Fix for #12081: missing translations in the js-translations.json #16892 - Merge Pull Request magento/magento2#16892 from mage2pratik/magento2:2.3-develop-PR-port-13528 - ... — committed to magento/magento2 by magento-engcom-team 6 years ago
- ENGCOM-2400: [Forwardport] Fix for #12081: missing translations in the js-translations.json #16892 — committed to magento/magento2 by sidolov 6 years ago
The reason why some strings are not translated is because they are by default only in html files in tags like
<translate args="'Item in Cart'" if="getCartLineItemsCount() === 1"/>The Magento Translation module has four different patterns it uses to detect translatable phrases. Only the translations for strings matching these patterns are translated into the js-translation.json. You can see the patterns in
Magento/Translation/etc/di.xml. Unfortunately none of those patterns match thetranslate argstags.To fix this without needing to explicitly call for a translation on all the missing phrases, you can add the following lines into pretty much any module’s di.xml:
This adds a pattern that matches the
translate argstags to the translation config.@magento-engcom-team Suggested fix for the issue is to add the above pattern (or something similar) to the relevant part of
Magento/Translation/etc/di.xml.I added file cart-items.html and this code. Now “Item in Cart” translating for different language works.
hi, any of solutions provided above doesnt work for me (M2.2.2). does anybody have working solution? thanks in advance!
The problem is that there was not js translation before
<translate>tag.I solved it temporary by overriding template src/vendor/magento/module-checkout/view/frontend/web/template/minicart/content.html
and add there js translation:
you can use any name for attribute here.
This solution works for me.