Files
FreshRSS/cli/i18n/I18nCompletionValidator.php
Alexis Degrugillier 127b7f0a3a Change i18n process (#4131)
Before, the ignore info were stored in a different file which was a bit cumbersome
for new comers. Now, this info is stored directly in the translation file as a
comment.

Before, there was no way of telling translators that a previously translated string
was in need of a new translation. Now, the dirty information is there to convey that
info.
2022-01-08 14:00:26 +01:00

52 lines
1.2 KiB
PHP

<?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() {
foreach ($this->reference as $file => $data) {
foreach ($data as $refKey => $refValue) {
$this->totalEntries++;
if (!array_key_exists($refKey, $this->language[$file])) {
$this->result .= "Missing key $refKey" . PHP_EOL;
continue;
}
$value = $this->language[$file][$refKey];
if ($value->isIgnore()) {
$this->passEntries++;
continue;
}
if ($refValue->equal($value)) {
$this->result .= "Untranslated key $refKey - $refValue" . PHP_EOL;
continue;
}
$this->passEntries++;
}
}
return $this->totalEntries === $this->passEntries;
}
}