32 $this->_phraseCollector = new \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer\PhraseCollector(
33 new \
Magento\Setup\Module\I18n\
Parser\Adapter\Php\Tokenizer(),
35 \
Magento\Framework\Phrase::class
42 .
'/Model/Js/DataProvider.php',
48 $incorrectNumberOfArgumentsErrors = [];
49 $missedPhraseErrors = [];
51 if (in_array($file, $this->blackList)) {
54 $this->_phraseCollector->parse($file);
56 foreach ($this->_phraseCollector->getPhrases() as $phrase) {
57 $this->checkEmptyPhrases($phrase, $missedPhraseErrors);
58 $this->checkArgumentMismatch($phrase, $incorrectNumberOfArgumentsErrors);
64 "\n%d missed phrases were discovered: \n%s",
65 count($missedPhraseErrors),
66 implode(
"\n\n", $missedPhraseErrors)
70 $incorrectNumberOfArgumentsErrors,
72 "\n%d usages of inconsistency the number of arguments and placeholders were discovered: \n%s",
73 count($incorrectNumberOfArgumentsErrors),
74 implode(
"\n\n", $incorrectNumberOfArgumentsErrors)
85 private function checkEmptyPhrases($phrase, &$missedPhraseErrors)
87 if (empty(trim($phrase[
'phrase'],
"'\"\t\n\r\0\x0B"))) {
98 private function checkArgumentMismatch($phrase, &$incorrectNumberOfArgumentsErrors)
100 if (preg_match_all(
'/%(\w+)/', $phrase[
'phrase'], $matches) || $phrase[
'arguments']) {
101 $placeholderCount = count(array_unique($matches[1]));
104 if (preg_match_all(
'/%((s)|([A-Za-z]+)%)/', $phrase[
'phrase'], $placeHolders, PREG_OFFSET_CAPTURE)) {
105 foreach ($placeHolders[0] as $ph) {
107 $charAfterPh = $phrase[
'phrase'][$ph[1] + strlen($ph[0])];
108 if (!preg_match(
'/[A-Za-z0-9]/', $charAfterPh)) {
114 if ($placeholderCount != $phrase[
'arguments']) {
_createMissedPhraseError($phrase)
_createPhraseError($phrase)