diff options
| author | 2017-11-04 21:17:08 +0100 | |
|---|---|---|
| committer | 2017-11-04 21:17:08 +0100 | |
| commit | 05b1901fcdbb051077d12f776980484d3b782970 (patch) | |
| tree | 1f005b468544ca6b16e9d1ac63c2d78b00812745 /cli/i18n/I18nCompletionValidator.php | |
| parent | fe84e6135e7bfb35085fafbc7191ba6306bdb20d (diff) | |
Move translation tools into the cli folder (#1673)
Translation tools must be used on cli. It is better to have them in the cli folder.
Diffstat (limited to 'cli/i18n/I18nCompletionValidator.php')
| -rw-r--r-- | cli/i18n/I18nCompletionValidator.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/cli/i18n/I18nCompletionValidator.php b/cli/i18n/I18nCompletionValidator.php new file mode 100644 index 000000000..2cb71acd5 --- /dev/null +++ b/cli/i18n/I18nCompletionValidator.php @@ -0,0 +1,49 @@ +<?php + +require_once __DIR__ . '/I18nValidatorInterface.php'; + +class I18nCompletionValidator implements I18nValidatorInterface { + + private $reference; + private $language; + private $totalEntries = 0; + private $passEntries = 0; + private $result = ''; + + public function __construct($reference, $language) { + $this->reference = $reference; + $this->language = $language; + } + + public function displayReport() { + return sprintf('Translation is %5.1f%% complete.', $this->passEntries / $this->totalEntries * 100) . PHP_EOL; + } + + public function displayResult() { + return $this->result; + } + + public function validate($ignore) { + foreach ($this->reference as $file => $data) { + foreach ($data as $key => $value) { + $this->totalEntries++; + if (is_array($ignore) && in_array($key, $ignore)) { + $this->passEntries++; + continue; + } + if (!array_key_exists($key, $this->language[$file])) { + $this->result .= sprintf('Missing key %s', $key) . PHP_EOL; + continue; + } + if ($value === $this->language[$file][$key]) { + $this->result .= sprintf('Untranslated key %s - %s', $key, $value) . PHP_EOL; + continue; + } + $this->passEntries++; + } + } + + return $this->totalEntries === $this->passEntries; + } + +} |
