aboutsummaryrefslogtreecommitdiff
path: root/cli/i18n/I18nUsageValidator.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2017-12-17 20:28:04 +0100
committerGravatar GitHub <noreply@github.com> 2017-12-17 20:28:04 +0100
commit60f56539c3f30fd3f7ba4f2a3570f7029ac93e5f (patch)
tree1e78bfac7042dceb63898e2215db8fb0c1d7745d /cli/i18n/I18nUsageValidator.php
parentceda55c75b158fc1cf4813fe0f258527754b9289 (diff)
parent0b1516af91792f86868689392f72ad4b6e32cdcf (diff)
Merge pull request #1720 from FreshRSS/dev
FreshRSS 1.9.0
Diffstat (limited to 'cli/i18n/I18nUsageValidator.php')
-rw-r--r--cli/i18n/I18nUsageValidator.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/cli/i18n/I18nUsageValidator.php b/cli/i18n/I18nUsageValidator.php
new file mode 100644
index 000000000..8ab934971
--- /dev/null
+++ b/cli/i18n/I18nUsageValidator.php
@@ -0,0 +1,47 @@
+<?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($ignore) {
+ 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 (is_array($ignore) && in_array($key, $ignore)) {
+ 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;
+ }
+
+}