|
@@ -18,14 +18,14 @@ discard block |
|
|
block discarded – undo |
|
18
|
18
|
public function __construct(?string $name = null) |
|
19
|
19
|
{ |
|
20
|
20
|
parent::__construct($name); |
|
21
|
|
- $this->translationFindConfig = require __DIR__ . '/Config.php'; |
|
|
21
|
+ $this->translationFindConfig = require __DIR__.'/Config.php'; |
|
22
|
22
|
} |
|
23
|
23
|
|
|
24
|
24
|
protected function configure() |
|
25
|
25
|
{ |
|
26
|
26
|
$this->setName('check:translations') |
|
27
|
27
|
->setDescription('Compare all translation keys with dictionaries(from files or api) for languages(default en_US)') |
|
28
|
|
- ->addArgument('config', InputArgument::REQUIRED, 'Path to config file. Instance of ' . CheckDictionariesConfig::class . ' have to be returned') |
|
|
28
|
+ ->addArgument('config', InputArgument::REQUIRED, 'Path to config file. Instance of '.CheckDictionariesConfig::class.' have to be returned') |
|
29
|
29
|
->addOption('params', null, InputOption::VALUE_REQUIRED, 'Params for config in format --params="a=b&c=d"') |
|
30
|
30
|
->addOption('include', null, InputOption::VALUE_REQUIRED, 'Params for translationFindConfig in format json --include="{"CLASS_ARGPOS_METHODS": {"Module": { "2": ["addResource"] }}}"') |
|
31
|
31
|
->addOption('exclude', null, InputOption::VALUE_REQUIRED, 'Params for translationFindConfig in format json --exclude="{"CLASS_ARGPOS_METHODS": {"Module": { "2": ["addResource"] }}}"'); |
|
@@ -36,7 +36,7 @@ discard block |
|
|
block discarded – undo |
|
36
|
36
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
37
|
37
|
{ |
|
38
|
38
|
if (!is_file($input->getArgument('config'))) { |
|
39
|
|
- throw new InvalidArgumentException('File "' . $input->getArgument('config') . '" does not exist'); |
|
|
39
|
+ throw new InvalidArgumentException('File "'.$input->getArgument('config').'" does not exist'); |
|
40
|
40
|
} |
|
41
|
41
|
parse_str($input->getOption('params'), $params); |
|
42
|
42
|
extract($params); |
|
@@ -46,7 +46,7 @@ discard block |
|
|
block discarded – undo |
|
46
|
46
|
throw $checkDictionariesConfig; |
|
47
|
47
|
} |
|
48
|
48
|
if (!$checkDictionariesConfig instanceof CheckDictionariesConfig) { |
|
49
|
|
- throw new InvalidConfigInstanceReturnedException('"' . (is_object($checkDictionariesConfig) ? get_class($checkDictionariesConfig) : $checkDictionariesConfig) . '" is not instance of ' . CheckDictionariesConfig::class); |
|
|
49
|
+ throw new InvalidConfigInstanceReturnedException('"'.(is_object($checkDictionariesConfig) ? get_class($checkDictionariesConfig) : $checkDictionariesConfig).'" is not instance of '.CheckDictionariesConfig::class); |
|
50
|
50
|
} |
|
51
|
51
|
|
|
52
|
52
|
$output->writeln(''); |
|
@@ -71,10 +71,10 @@ discard block |
|
|
block discarded – undo |
|
71
|
71
|
break; |
|
72
|
72
|
} |
|
73
|
73
|
foreach ($dictionaries as $lang => $dictionary) { |
|
74
|
|
- $langText = !$onlyOneLang ? ' for language "' . $lang . '"' : ''; |
|
|
74
|
+ $langText = !$onlyOneLang ? ' for language "'.$lang.'"' : ''; |
|
75
|
75
|
if (!isset($dictionary[$key])) { |
|
76
|
76
|
$errors[] = sprintf( |
|
77
|
|
- 'Missing translation for key "%s" ' . $langText . 'in file: %s:%s' . (isset($call['call']) ? ' call: "%s"' : '%s'), |
|
|
77
|
+ 'Missing translation for key "%s" '.$langText.'in file: %s:%s'.(isset($call['call']) ? ' call: "%s"' : '%s'), |
|
78
|
78
|
$key, |
|
79
|
79
|
$call['file'], |
|
80
|
80
|
$call['line'], |
|
@@ -84,10 +84,10 @@ discard block |
|
|
block discarded – undo |
|
84
|
84
|
// find plural bad key |
|
85
|
85
|
$dictionaryTranslate = $dictionary[$key]; |
|
86
|
86
|
$pluralKey = $call['arg'] ?? null; |
|
87
|
|
- $pluralKeyInFile = $pluralKey ? '%' . $pluralKey . '%' : null; |
|
|
87
|
+ $pluralKeyInFile = $pluralKey ? '%'.$pluralKey.'%' : null; |
|
88
|
88
|
if ($pluralKey && strpos($dictionaryTranslate, $pluralKeyInFile) === false) { |
|
89
|
89
|
$errors[] = sprintf( |
|
90
|
|
- 'Translation key "%s" ' . $langText . 'in file: %s:%s call: "%s" has bad plural key: %s for translation: "%s"', |
|
|
90
|
+ 'Translation key "%s" '.$langText.'in file: %s:%s call: "%s" has bad plural key: %s for translation: "%s"', |
|
91
|
91
|
$key, |
|
92
|
92
|
$call['file'], |
|
93
|
93
|
$call['line'], |
|
@@ -98,7 +98,7 @@ discard block |
|
|
block discarded – undo |
|
98
|
98
|
} |
|
99
|
99
|
if ($pluralKey === null && preg_match('/.*%.+%.*/', $dictionaryTranslate) === false) { |
|
100
|
100
|
$errors[] = sprintf( |
|
101
|
|
- 'Translation key "%s" ' . $langText . 'in file: %s:%s call: "%s" has missing plural key for translation: "%s"', |
|
|
101
|
+ 'Translation key "%s" '.$langText.'in file: %s:%s call: "%s" has missing plural key for translation: "%s"', |
|
102
|
102
|
$key, |
|
103
|
103
|
$call['file'], |
|
104
|
104
|
$call['line'], |
|
@@ -115,7 +115,7 @@ discard block |
|
|
block discarded – undo |
|
115
|
115
|
} |
|
116
|
116
|
|
|
117
|
117
|
$output->writeln(''); |
|
118
|
|
- $output->writeln('<comment>' . count($errors) . ' errors found</comment>'); |
|
|
118
|
+ $output->writeln('<comment>'.count($errors).' errors found</comment>'); |
|
119
|
119
|
return count($errors); |
|
120
|
120
|
} |
|
121
|
121
|
|