Skip to content

Commit 98ed69c

Browse files
author
Yuri Kovsher
committed
MAGETWO-33062: Update dictionary search tool to support \Magento\Framework\Phrase
1 parent f7ae824 commit 98ed69c

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

dev/tools/Magento/Tools/I18n/Parser/Adapter/Php/Tokenizer/PhraseCollector.php

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,23 +77,47 @@ public function parse($file, $searchObjects = false)
7777
protected function _extractPhrases($searchObjects)
7878
{
7979
if ($firstToken = $this->_tokenizer->getNextRealToken()) {
80-
if ($firstToken->isEqualFunction('__')) {
81-
$secondToken = $this->_tokenizer->getNextRealToken();
82-
if ($secondToken && $secondToken->isOpenBrace()) {
83-
$arguments = $this->_tokenizer->getFunctionArgumentsTokens();
84-
$phrase = $this->_collectPhrase(array_shift($arguments));
85-
if (null !== $phrase) {
86-
$this->_addPhrase($phrase, count($arguments), $this->_file, $firstToken->getLine());
87-
}
88-
}
89-
} elseif ($searchObjects && $firstToken->isNew() && $this->_tokenizer->isMatchingClass('Phrase')) {
80+
if (!$this->extractMethodPhrase($firstToken) && $searchObjects) {
81+
$this->extractObjectPhrase($firstToken);
82+
}
83+
}
84+
}
85+
86+
/**
87+
* @param Token $firstToken
88+
* @return bool
89+
*/
90+
protected function extractMethodPhrase(Token $firstToken)
91+
{
92+
if ($firstToken->isEqualFunction('__')) {
93+
$secondToken = $this->_tokenizer->getNextRealToken();
94+
if ($secondToken && $secondToken->isOpenBrace()) {
9095
$arguments = $this->_tokenizer->getFunctionArgumentsTokens();
9196
$phrase = $this->_collectPhrase(array_shift($arguments));
9297
if (null !== $phrase) {
9398
$this->_addPhrase($phrase, count($arguments), $this->_file, $firstToken->getLine());
99+
return true;
94100
}
95101
}
96102
}
103+
return false;
104+
}
105+
106+
/**
107+
* @param Token $firstToken
108+
* @return bool
109+
*/
110+
protected function extractObjectPhrase(Token $firstToken)
111+
{
112+
if ($firstToken->isNew() && $this->_tokenizer->isMatchingClass('Phrase')) {
113+
$arguments = $this->_tokenizer->getFunctionArgumentsTokens();
114+
$phrase = $this->_collectPhrase(array_shift($arguments));
115+
if (null !== $phrase) {
116+
$this->_addPhrase($phrase, count($arguments), $this->_file, $firstToken->getLine());
117+
return true;
118+
}
119+
}
120+
return false;
97121
}
98122

99123
/**

0 commit comments

Comments
 (0)