Skip to content

Commit 77daafd

Browse files
committed
Fix #11175 - i18n:collect-phrases -m can't find many important magento phrases - made patterns case-sensitive because translations does not work with uppercase bindings/tags/function names
1 parent 754ea5f commit 77daafd

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,19 @@ class Html extends AbstractAdapter
2222
* @deprecated Not used anymore because of newly introduced constant
2323
* @see self::HTML_REGEX_LIST
2424
*/
25-
const HTML_FILTER = "/i18n:\s?'(?<value>[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/i";
25+
const HTML_FILTER = "/i18n:\s?'(?<value>[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/";
2626

2727
private const HTML_REGEX_LIST = [
2828
// <span><!-- ko i18n: 'Next'--><!-- /ko --></span>
2929
// <th class="col col-method" data-bind="i18n: 'Select Method'"></th>
30-
"/i18n:\s?'(?<value>[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/i",
30+
"/i18n:\s?'(?<value>[^'\\\\]*(?:\\\\.[^'\\\\]*)*)'/",
3131
// <translate args="'System Messages'"/>
3232
// <span translate="'Examples'"></span>
33-
"/translate( args|)=\"'(?<value>[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)'\"/i",
33+
"/translate( args|)=\"'(?<value>[^\"\\\\]*(?:\\\\.[^\"\\\\]*)*)'\"/",
3434
// <a data-bind="attr: { title: $t('This is \' test \' data'), href: '#'} "></a>
3535
// <input type="text" data-bind="attr: { placeholder: $t('Placeholder'), title: $t('Title') }" />
3636
// 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'
37+
'/\\$t\(\s*([\'"])(?<value>.*?[^\\\])\1.*?[),]/'
3838
];
3939

4040
/**

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function testParse()
4949
'line' => '',
5050
'quote' => '',
5151
],
52+
// `I18N` is not parsed - bindings are case-sensitive
5253
[
5354
'phrase' => 'This is test data at right side of attr',
5455
'file' => $this->testFile,
@@ -97,12 +98,15 @@ public function testParse()
9798
'line' => '',
9899
'quote' => '',
99100
],
101+
// `<TRANSLATE>` tag is not parsed - only lowercase tags are accepted
100102
[
101103
'phrase' => 'This is test content in translate attribute',
102104
'file' => $this->testFile,
103105
'line' => '',
104106
'quote' => '',
105107
],
108+
// `TRANSLATE` attribute is not parsed - only lowercase attribute names are accepted
109+
// `$T()` is not parsed - function names in JS are case-sensitive
106110
[
107111
// en_US.csv: "This is ' test ' data for attribute translation with single quotes","This is ' test ' data for attribute translation with single quotes"
108112
'phrase' => 'This is \\\' test \\\' data for attribute translation with single quotes',

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
@@ -21,6 +21,7 @@
2121
}}
2222
</span>
2323
<label data-bind="i18n: 'This is test data', attr: {for: 'more-test-data-'}"></label>
24+
<label data-bind="I18N: 'This is test data with uppercase binding', attr: {for: 'more-test-data-'}"></label>
2425
<label data-bind="attr: {for: 'more-test-data-' + $parent.getCode()}"><span data-bind="i18n: 'This is test data at right side of attr'"></span></label>
2526
<label data-bind="i18n: 'This is \' test \' data', attr: {for: 'more-test-data-' + $parent.getCode()}"></label>
2627
<label data-bind="i18n: 'This is \" test \" data', attr: {for: 'more-test-data-' + $parent.getCode()}"></label>
@@ -30,7 +31,10 @@
3031
<label data-bind="i18n: '\''"></label>
3132
<label data-bind="i18n: '\\\\ '"></label>
3233
<span><translate args="'This is test content in translate tag'" /></span>
34+
<span><TRANSLATE args="'This is test content in the uppercase translate tag'" /></span>
3335
<span translate="'This is test content in translate attribute'"></span>
36+
<span TRANSLATE="'This is test content in uppercase translate attribute'"></span>
37+
<a data-bind="attr: { title: $T('This is test data for invalid attribute translation'), href: '#'} "></a>
3438
<a data-bind="attr: { title: $t('This is \' test \' data for attribute translation with single quotes'), href: '#'} "></a>
3539
<a data-bind="attr: { title: $t('This is test data for attribute translation with a quote after\'\''), href: '#'} "></a>
3640
<a data-bind="attr: { title: $t('This is test data for attribute translation with a quote after\' \' '), href: '#'} "></a>

0 commit comments

Comments
 (0)