Description
This issue is automatically created based on existing pull request: #31804: Fix #11175 - i18n:collect-phrases -m can't find many important Magento phrases - added parsing of the attr translations via $t('Text')
Description (*)
According to the official Magento 2 documentations, there is a way to translate HTML attributes, but this is not covered as well. Here is a text from the documentation:
When a string is added as an attribute of an HTML element:
<input type="text" data-bind="attr: {placeholder: $t('First Name')}" />
Documentation - Strings added in UI component templates
This was of translating attributes does not seem to be used in the Magento 2 itself (if my search is correct). Though,
it is officially documented, is used by some vendors and it can be found in some Q&A on the Internet
(like here - magento.stackexchange.com)
Related Pull Requests
Fixed Issues (if relevant)
- Fixes i18n:collect-phrases -m can't find many important magento phrases #11175 - i18n:collect-phrases -m can't find many important magento phrases
Manual testing scenarios (*)
- Add the following code to any Magento
.html
file, for exampleapp/code/Magento/Catalog/view/frontend/web/template/product/addtocart-button.html
<a data-bind="attr: { title: $t('This is \' test \' data for attribute translation with single quotes'), href: '#'} "></a>
<a data-bind="attr: { title: $t('This is test data for attribute translation with a quote after\'\''), href: '#'} "></a>
<a data-bind="attr: { title: $t('This is test data for attribute translation with a quote after\' \' '), href: '#'} "></a>
<input type="text" data-bind="attr: { placeholder: $t('Attribute translation - Placeholder'), title: $t('Attribute translation - Title') }" />
- Run the command
php bin/magento i18n:collect-phrases app/code/Magento/Catalog/view/frontend/web/template/product/
Expected result: Command output contains phrases in the $t('Text')
translations that cat be then used in the i18n files.
i18n output example:
"This is ' test ' data for attribute translation with single quotes","This is ' test ' data for attribute translation with single quotes"
"This is test data for attribute translation with a quote after''","This is test data for attribute translation with a quote after''"
"This is test data for attribute translation with a quote after' ' ","This is test data for attribute translation with a quote after' ' "
"This is "" test "" data with 'href' after translate","This is "" test "" data with 'href' after translate"
Actual result: The above phrases are not present in the output.
Questions or comments
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 are green)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status