Skip to content

Commit e925bf7

Browse files
author
Oleksii Korshenko
committed
MAGETWO-47439: [Github] i18n:collect-phrases -m can't find many important magento phrases #2630
- added support of $t("some text") - added support of xml attributes translation
1 parent b5fa3c0 commit e925bf7

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

setup/src/Magento/Setup/Module/I18n/Dictionary/Phrase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ private function getCompiledString($string)
270270
{
271271
$encloseQuote = $this->getQuote() == Phrase::QUOTE_DOUBLE ? Phrase::QUOTE_DOUBLE : Phrase::QUOTE_SINGLE;
272272
//find all occurrences of ' and ", with no \ before it.
273-
preg_match_all('/(?<!\\\\)[\'"]/', $string, $matches);
274-
if (count($matches[0]) % 2 !== 0) {
273+
preg_match_all('/[^\\\\]' . $encloseQuote . '/', $string, $matches);
274+
if (count($matches[0])) {
275275
$string = addslashes($string);
276276
}
277277
$evalString = 'return ' . $encloseQuote . $string . $encloseQuote . ';';

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ protected function _parse()
2828
$this->_addPhrase($quote . $results[$i][2] . $quote, $lineNumber);
2929
}
3030
}
31+
32+
preg_match_all('/\\$t\(\s*([\'"])(.*?[^\\\])\1.*?[),]/', $fileRow, $results, PREG_SET_ORDER);
33+
for ($i = 0; $i < count($results); $i++) {
34+
if (isset($results[$i][2])) {
35+
$quote = $results[$i][1];
36+
$this->_addPhrase($quote . $results[$i][2] . $quote, $lineNumber);
37+
}
38+
}
3139
}
3240
fclose($fileHandle);
3341
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ protected function _parse()
3333
if ($phrase) {
3434
$this->_addPhrase($phrase);
3535
}
36+
$elementAttributes = $element->attributes();
37+
if (isset($elementAttributes[$value])) {
38+
$phrase = (string)$elementAttributes[$value];
39+
if ($phrase) {
40+
$this->_addPhrase($phrase);
41+
}
42+
}
3643
}
3744
}
3845
}

0 commit comments

Comments
 (0)