diff options
| author | 2022-10-20 17:42:47 -0400 | |
|---|---|---|
| committer | 2022-10-20 23:42:47 +0200 | |
| commit | 1f4e347cae51667e7cf5772aef55d274a39c8023 (patch) | |
| tree | 86ba1032c30b581223a7131764d8384f4b566d88 /cli/i18n/I18nCompletionValidator.php | |
| parent | d4181e098d93379c21251bd94d1397e16e56218a (diff) | |
Add tests on i18n classes (#4756)
Diffstat (limited to 'cli/i18n/I18nCompletionValidator.php')
| -rw-r--r-- | cli/i18n/I18nCompletionValidator.php | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cli/i18n/I18nCompletionValidator.php b/cli/i18n/I18nCompletionValidator.php index ee4ab9f78..000629f8d 100644 --- a/cli/i18n/I18nCompletionValidator.php +++ b/cli/i18n/I18nCompletionValidator.php @@ -16,6 +16,12 @@ class I18nCompletionValidator implements I18nValidatorInterface { } public function displayReport() { + if ($this->passEntries > $this->totalEntries) { + throw new \RuntimeException('The number of translated strings cannot be higher than the number of strings'); + } + if ($this->totalEntries === 0) { + return 'There is no data.' . PHP_EOL; + } return sprintf('Translation is %5.1f%% complete.', $this->passEntries / $this->totalEntries * 100) . PHP_EOL; } @@ -27,7 +33,7 @@ class I18nCompletionValidator implements I18nValidatorInterface { foreach ($this->reference as $file => $data) { foreach ($data as $refKey => $refValue) { $this->totalEntries++; - if (!array_key_exists($refKey, $this->language[$file])) { + if (!array_key_exists($file, $this->language) || !array_key_exists($refKey, $this->language[$file])) { $this->result .= "Missing key $refKey" . PHP_EOL; continue; } |
