Skip to content

[Issue] Fix #11175 - i18n:collect-phrases -m can't find many important Magento phrases - added parsing of the attr translations via $t('Text') #31873

Closed
@m2-assistant

Description

@m2-assistant

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

48216f3

Fixed Issues (if relevant)

  1. 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 (*)

  1. Add the following code to any Magento .html file, for example app/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') }" />
  1. 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

Component: SetupFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions