Skip to content

Commit 893e4f2

Browse files
Anton Evershostep
authored andcommitted
Backport of PR-10445 for Magento 2.1: Fix JS translation search
Don't only replace \' but also \" with ' and " (cherry picked from commit a150d24) Concatenate JS translations before translating them This enables support for $.mage.__("concatenating" + "strings"); (cherry picked from commit c79b583) +: put all regexes in cdata tags (cherry picked from commit f930471) Prevent translation string lookup from breaking on \' or \" with a negative lookbehind (cherry picked from commit 87d4ba4) Support $.mage.__('') as well as jQuery.mage.__('') (cherry picked from commit 5ae47df)
1 parent ca240ab commit 893e4f2

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ protected function getPhrases($content)
124124
{
125125
$phrases = [];
126126
foreach ($this->config->getPatterns() as $pattern) {
127-
$result = preg_match_all($pattern, $content, $matches);
127+
$concatenatedContent = preg_replace('~(["\'])\s*?\+\s*?\1~', '', $content);
128+
$result = preg_match_all($pattern, $concatenatedContent, $matches);
128129

129130
if ($result) {
130131
if (isset($matches[2])) {
131132
foreach ($matches[2] as $match) {
132-
$phrases[] = str_replace('\\\'', '\'', $match);
133+
$phrases[] = str_replace(["\'", '\"'], ["'", '"'], $match);
133134
}
134135
}
135136
}

app/code/Magento/Translation/etc/di.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
<argument name="patterns" xsi:type="array">
6060
<item name="i18n_translation" xsi:type="string"><![CDATA[~i18n\:\s*(["'])(.*?)(?<!\\)\1~]]></item>
6161
<item name="translate_wrapping" xsi:type="string"><![CDATA[~translate\=("')([^\'].*?)\'\"~]]></item>
62-
<item name="mage_translation_widget" xsi:type="string">~\$\.mage\.__\((?s)[^'"]*?(['"])(.+?)\1(?s).*?\)~</item>
63-
<item name="mage_translation_static" xsi:type="string">~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~</item>
62+
<item name="mage_translation_widget" xsi:type="string"><![CDATA[~(?:\$|jQuery)\.mage\.__\((?s)[^'"]*?(['"])(.+?)(?<!\\)\1(?s).*?\)~]]></item>
63+
<item name="mage_translation_static" xsi:type="string"><![CDATA[~\$t\((?s)[^'"]*?(["'])(.+?)\1(?s).*?\)~]]></item>
6464
</argument>
6565
</arguments>
6666
</type>

0 commit comments

Comments
 (0)