Skip to content

Commit 754ea5f

Browse files
committed
Fix #11175 - i18n:collect-phrases -m can't find many important magento phrases - added parsing of the attr translations via $t('Text')
1 parent 1c78cdb commit 754ea5f

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

setup/src/Magento/Setup/Module/I18n/Parser/Adapter/Html.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ class Html extends AbstractAdapter
3030
"/i18n:\s?'(?<value>[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/i",
3131
// <translate args="'System Messages'"/>
3232
// <span translate="'Examples'"></span>
33-
"/translate( args|)=\"'(?<value>[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)'\"/i"
33+
"/translate( args|)=\"'(?<value>[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)'\"/i",
34+
// <a data-bind="attr: { title: $t('This is \' test \' data'), href: '#'} "></a>
35+
// <input type="text" data-bind="attr: { placeholder: $t('Placeholder'), title: $t('Title') }" />
36+
// Double quotes are not handled correctly in the `attr` binding. Move phrase to the UI component property if needed
37+
'/\\$t\(\s*([\'"])(?<value>.*?[^\\\])\1.*?[),]/i'
3438
];
3539

3640
/**

setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/HtmlTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,41 @@ public function testParse()
103103
'line' => '',
104104
'quote' => '',
105105
],
106+
[
107+
// en_US.csv: "This is ' test ' data for attribute translation with single quotes","This is ' test ' data for attribute translation with single quotes"
108+
'phrase' => 'This is \\\' test \\\' data for attribute translation with single quotes',
109+
'file' => $this->testFile,
110+
'line' => '',
111+
'quote' => '',
112+
],
113+
[
114+
// en_US.csv: "This is test data for attribute translation with a quote after''","This is test data for attribute translation with a quote after''"
115+
'phrase' => 'This is test data for attribute translation with a quote after\\\'\\\'',
116+
'file' => $this->testFile,
117+
'line' => '',
118+
'quote' => '',
119+
],
120+
[
121+
// en_US.csv: "This is test data for attribute translation with a quote after' ' ","This is test data for attribute translation with a quote after' ' "
122+
'phrase' => 'This is test data for attribute translation with a quote after\\\' \\\' ',
123+
'file' => $this->testFile,
124+
'line' => '',
125+
'quote' => '',
126+
],
127+
[
128+
// en_US.csv: "Attribute translation - Placeholder","Attribute translation - Placeholder"
129+
'phrase' => 'Attribute translation - Placeholder',
130+
'file' => $this->testFile,
131+
'line' => '',
132+
'quote' => '',
133+
],
134+
[
135+
// en_US.csv: "Attribute translation - Title","Attribute translation - Title"
136+
'phrase' => 'Attribute translation - Title',
137+
'file' => $this->testFile,
138+
'line' => '',
139+
'quote' => '',
140+
]
106141
];
107142

108143
$this->model->parse($this->testFile);

setup/src/Magento/Setup/Test/Unit/Module/I18n/Parser/Adapter/_files/email.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,9 @@
3131
<label data-bind="i18n: '\\\\ '"></label>
3232
<span><translate args="'This is test content in translate tag'" /></span>
3333
<span translate="'This is test content in translate attribute'"></span>
34+
<a data-bind="attr: { title: $t('This is \' test \' data for attribute translation with single quotes'), href: '#'} "></a>
35+
<a data-bind="attr: { title: $t('This is test data for attribute translation with a quote after\'\''), href: '#'} "></a>
36+
<a data-bind="attr: { title: $t('This is test data for attribute translation with a quote after\' \' '), href: '#'} "></a>
37+
<input type="text" data-bind="attr: { placeholder: $t('Attribute translation - Placeholder'), title: $t('Attribute translation - Title') }" />
3438
</body>
3539
</html>

0 commit comments

Comments
 (0)