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

Fix translations #15623

Conversation

cherednichenkoa
Copy link
Contributor

@cherednichenkoa cherednichenkoa commented May 31, 2018

Fix unsupported translate tags in mini cart content

Description

Minicart template has several usages of <tranlsate /> tags , however according to this
Config (that has inside defined preg expressions for translator template parser)

            <argument name="patterns" xsi:type="array">
                <item name="i18n_translation" xsi:type="string"><![CDATA[~i18n\:\s*(["'])(.*?)(?<!\\)\1~]]></item>
                <item name="translate_wrapping" xsi:type="string"><![CDATA[~translate\=("')([^\'].*?)\'\"~]]></item>
                <item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?:\$|jQuery)\.mage\.__\((?s)[^'"]*?(['"])(.+?)(?<!\\)\1(?s).*?\)~]]></item>
                <item name="mage_translation_static" xsi:type="string"><![CDATA[~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~]]></item>
            </argument>

Magento supports such definition of translate attribute <span translate="'Text to translate'"> but not the tag ,
this tag will be translated without problem on frontend, if such translation has additiona properl definitions
When magento initialize translations for FE, and put it in Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME file , it parses templates to get proper set of translations, in case template has definition, it will not match preg's, so it will not be translated on frontend

Fixed Issues (if relevant)

  1. "Item in cart" translation does not work
    Magento has around 20 definitions of <template /> tag, so it does not make sense to add additional preg to create additional load for template parser, only for 20 templates

Manual testing scenarios

  1. Create additional locale
  2. Add own label + translation in locale csv (for exaple "My custom text")
  3. And this text to KO template via "<translate />" tag
  4. This translate will not not work

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented May 31, 2018

CLA assistant check
All committers have signed the CLA.

@VladimirZaets
Copy link
Contributor

@cherednichenkoa Yes, JS will not translate phrases that don't exist in CSV file, but after command bin/magento i18n:collect-phrases all phrases that should be translated will be added to CSV file. I'm not sure that your fix can affect it, I'm investigating it now.

@cherednichenkoa
Copy link
Contributor Author

cherednichenkoa commented Jun 1, 2018

@VladimirZaets , I am debugging it now

@cherednichenkoa
Copy link
Contributor Author

cherednichenkoa commented Jun 1, 2018

@VladimirZaets I quick went thru debugger , and here is what I have found

Take a look at this file - this cli command uses it to parse html templates (it is our case)
https://github.com/magento/magento2/blob/2.2-develop/setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php

This is preg match used to parse .html templates for translation, as you can see, it does not cover all cases that magento uses on frontend translates
`
/**
* Covers
*
*
/
const HTML_FILTER = "/i18n:\s?'(?[^'\\\\]
(?:\\.[^'\\\\]))'/i";

`
You can try to parse content of file I have modified with this preg match, it will not find anything

Here is list of patters that magento uses to build js-tranlations.json for frontend , as you may see it has more types of translates it covers
<argument name="patterns" xsi:type="array"> <item name="i18n_translation" xsi:type="string"><![CDATA[~i18n\:\s*(["'])(.*?)(?<!\\)\1~]]></item> <item name="translate_wrapping" xsi:type="string"><![CDATA[~translate\=("')([^\'].*?)\'\"~]]></item> <item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?:\$|jQuery)\.mage\.__\((?s)[^'"]*?(['"])(.+?)(?<!\\)\1(?s).*?\)~]]></item> <item name="mage_translation_static" xsi:type="string"><![CDATA[~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~]]></item> </argument>

I think it is problem with different flow for this command and Magento js-translations.json logic,we can add more pattens thru di.xml to this parser, what do you think ?

I will double check it later, that what I have found now, hope it will help you

@VladimirZaets
Copy link
Contributor

@cherednichenkoa I think they have a different responsibility, before adding new patterns we should fully understand of use cases.
Anyway, it exceeds the scope of the current task.

@cherednichenkoa
Copy link
Contributor Author

@VladimirZaets okay, you are trying to test my change with this console command, I have checked why it works so, what are the our further steps ? Not sure that I am clear what is wrong for now

@VladimirZaets
Copy link
Contributor

@cherednichenkoa I will merge your PR. The fix looks fine. Also, I will investigate the reason why CLI command works incorrectly.
Will be great if you try to investigate it and will create new one PR with the solution for this issue.

@cherednichenkoa
Copy link
Contributor Author

@VladimirZaets , ok got it, I will check it for sure

@magento-engcom-team magento-engcom-team merged commit 4f1b50b into magento:2.3-develop Jun 2, 2018
magento-engcom-team pushed a commit that referenced this pull request Jun 2, 2018
@magento-engcom-team
Copy link
Contributor

Hi @cherednichenkoa. Thank you for your contribution.
Changes from your Pull Request will be available with the upcoming 2.3.0 release.

VitaliyBoyko added a commit to VitaliyBoyko/magento2 that referenced this pull request Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants