Skip to content

Commit ca71b88

Browse files
committed
Merging remote-tracking branch 'sprank/35449-fix-i18n-collect-phrases-command' into AC-3499
2 parents 5dd75c7 + b8cd234 commit ca71b88

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/expectedPhrases.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@
1818
"string with escaped ""double quotes""","string with escaped ""double quotes"""
1919
"string with placeholder in escaped double quotes ""%1""","string with placeholder in escaped double quotes ""%1"""
2020
"string that's got an unclosed single quote in it","string that's got an unclosed single quote in it"
21+
"Thank you for your order from %store_name.","Thank you for your order from %store_name."
22+
"Our hours are <span class=""no-link"">%store_hours</span>.","Our hours are <span class=""no-link"">%store_hours</span>."
23+
"Translation inside if directive","Translation inside if directive"
2124
"Test di text","Test di text"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
8+
{{template config_path="design/email/header_template"}}
9+
10+
<table>
11+
<tr class="email-intro">
12+
<td>
13+
<p>
14+
{{trans "Thank you for your order from %store_name." store_name=$store.frontend_name}}
15+
</p>
16+
<p>
17+
{{depend store_hours}}
18+
{{trans 'Our hours are <span class="no-link">%store_hours</span>.' store_hours=$store_hours |raw}}
19+
{{/depend}}
20+
</p>
21+
{{if something}}
22+
<p>{{trans 'Translation inside if directive'}}</p>
23+
{{/if}}
24+
</td>
25+
</tr>
26+
</table>
27+
28+
{{template config_path="design/email/footer_template"}}

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

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

2727
/**
2828
* Covers
@@ -50,6 +50,21 @@ protected function _parse()
5050
throw new Exception('Failed to load file from disk.');
5151
}
5252

53+
$this->extractPhrasesFromTransDirective($data);
54+
$this->extractPhrases(self::REGEX_I18N_BINDING, $data, 2, 1);
55+
$this->extractPhrases(self::REGEX_TRANSLATE_TAG_OR_ATTR, $data, 3, 2);
56+
$this->extractPhrases(Js::REGEX_TRANSLATE_FUNCTION, $data, 3, 2);
57+
}
58+
59+
/**
60+
* Extracts all phrases from trans directives in the given string.
61+
*
62+
* @param string $data
63+
*
64+
* @return void
65+
*/
66+
private function extractPhrasesFromTransDirective(string $data): void
67+
{
5368
$results = [];
5469
preg_match_all(Filter::CONSTRUCTION_PATTERN, $data, $results, PREG_SET_ORDER);
5570
for ($i = 0, $count = count($results); $i < $count; $i++) {
@@ -61,15 +76,16 @@ protected function _parse()
6176

6277
$quote = $directive[1];
6378
$this->_addPhrase($quote . $directive[2] . $quote);
79+
} elseif (in_array($results[$i][1], ['depend', 'if'], true) && isset($results[$i][3])) {
80+
// make sure to process trans directives nested inside depend / if directives
81+
$this->extractPhrasesFromTransDirective($results[$i][3]);
6482
}
6583
}
66-
67-
$this->extractPhrases(self::REGEX_I18N_BINDING, $data, 2, 1);
68-
$this->extractPhrases(self::REGEX_TRANSLATE_TAG_OR_ATTR, $data, 3, 2);
69-
$this->extractPhrases(Js::REGEX_TRANSLATE_FUNCTION, $data, 3, 2);
7084
}
7185

7286
/**
87+
* Extracts all phrases with the given regex in the given string.
88+
*
7389
* @param string $regex
7490
* @param string $data
7591
* @param int $expectedGroupsCount

0 commit comments

Comments
 (0)