mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-02-25 19:16:38 -05:00
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.
45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php
|
|
|
|
require_once __DIR__ . '/I18nValidatorInterface.php';
|
|
|
|
class I18nUsageValidator implements I18nValidatorInterface {
|
|
|
|
private $code;
|
|
private $reference;
|
|
private $totalEntries = 0;
|
|
private $failedEntries = 0;
|
|
private $result = '';
|
|
|
|
public function __construct($reference, $code) {
|
|
$this->code = $code;
|
|
$this->reference = $reference;
|
|
}
|
|
|
|
public function displayReport() {
|
|
return sprintf('%5.1f%% of translation keys are unused.', $this->failedEntries / $this->totalEntries * 100) . PHP_EOL;
|
|
}
|
|
|
|
public function displayResult() {
|
|
return $this->result;
|
|
}
|
|
|
|
public function validate() {
|
|
foreach ($this->reference as $file => $data) {
|
|
foreach ($data as $key => $value) {
|
|
$this->totalEntries++;
|
|
if (preg_match('/\._$/', $key) && in_array(preg_replace('/\._$/', '', $key), $this->code)) {
|
|
continue;
|
|
}
|
|
if (!in_array($key, $this->code)) {
|
|
$this->result .= sprintf('Unused key %s - %s', $key, $value) . PHP_EOL;
|
|
$this->failedEntries++;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0 === $this->failedEntries;
|
|
}
|
|
|
|
}
|