Skip to content

Fix unsupported <translate tags #15207

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

Closed
wants to merge 2 commits into from
Closed

Fix unsupported <translate tags #15207

wants to merge 2 commits into from

Conversation

cherednichenkoa
Copy link
Contributor

@cherednichenkoa cherednichenkoa commented May 14, 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)

@VladimirZaets
Copy link
Contributor

Hi, @cherednichenkoa, I took your PR into processing, thank you for collaboration.

@magento-engcom-team
Copy link
Contributor

@cherednichenkoa thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

data_flag used for several proposes, a but main is to save app:config:import data as a system_config_snapshot, if store has several scopes + multiple extensions, it can be not enough to save config snapshot
@VladimirZaets
Copy link
Contributor

Hi @cherednichenkoa.
We tried to test your fix and the following scenario is failed:

Problems: PR doesn't fix "Item in cart" translation.
Steps to reproduce:
Add Spanish locale.
Run php bin/magento i18n:collect-phrases -o "/var/www/html/magento2ce/pr/app/i18n/mageplaza/es_AR/es_AR.csv" -m
View app/i18n/mageplaza/es_AR/es_AR.csv file.
Expected result:
Csv file contains "Item in cart" phrase.
Actual result:
There is no "Item in cart" phrase in csv file.

Also, can you please explain how "data_flag" effects case with translation?

@cherednichenkoa
Copy link
Contributor Author

cherednichenkoa commented May 31, 2018

Hello @VladimirZaets ,
regarding flag_data - it is my bad, I have done commit with flag_data thru github ui, it accidentally went to the same branch with tranlsates
I have re-pushed it to the separate branch #15623
Let's close this PR and continue discussion here #15623
Regarding - test scenario failed .
Can you check again translate file , it does not have 'Item in cart' phrase ? not sure what is wrong in my fix ?
https://github.com/raw/mageplaza/magento-2-spanish-language-pack/master/es_AR.csv
If they do not have this translation, JS will not be translated, is not it ?

@okorshenko okorshenko removed this from the May 2018 milestone May 31, 2018
@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.

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