aboutsummaryrefslogtreecommitdiff
path: root/cli/i18n
diff options
context:
space:
mode:
Diffstat (limited to 'cli/i18n')
-rw-r--r--cli/i18n/I18nCompletionValidator.php8
-rw-r--r--cli/i18n/I18nFile.php11
-rw-r--r--cli/i18n/I18nUsageValidator.php6
3 files changed, 15 insertions, 10 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;
}
diff --git a/cli/i18n/I18nFile.php b/cli/i18n/I18nFile.php
index a7045459c..fca31d662 100644
--- a/cli/i18n/I18nFile.php
+++ b/cli/i18n/I18nFile.php
@@ -3,16 +3,9 @@
require_once __DIR__ . '/I18nValue.php';
class I18nFile {
-
- private $i18nPath;
-
- public function __construct() {
- $this->i18nPath = __DIR__ . '/../../app/i18n';
- }
-
public function load() {
$i18n = array();
- $dirs = new DirectoryIterator($this->i18nPath);
+ $dirs = new DirectoryIterator(I18N_PATH);
foreach ($dirs as $dir) {
if ($dir->isDot()) {
continue;
@@ -32,7 +25,7 @@ class I18nFile {
public function dump(array $i18n) {
foreach ($i18n as $language => $file) {
- $dir = $this->i18nPath . DIRECTORY_SEPARATOR . $language;
+ $dir = I18N_PATH . DIRECTORY_SEPARATOR . $language;
if (!file_exists($dir)) {
mkdir($dir);
}
diff --git a/cli/i18n/I18nUsageValidator.php b/cli/i18n/I18nUsageValidator.php
index 2e402faf0..681e17326 100644
--- a/cli/i18n/I18nUsageValidator.php
+++ b/cli/i18n/I18nUsageValidator.php
@@ -16,6 +16,12 @@ class I18nUsageValidator implements I18nValidatorInterface {
}
public function displayReport() {
+ if ($this->failedEntries > $this->totalEntries) {
+ throw new \RuntimeException('The number of unused strings cannot be higher than the number of strings');
+ }
+ if ($this->totalEntries === 0) {
+ return 'There is no data.' . PHP_EOL;
+ }
return sprintf('%5.1f%% of translation keys are unused.', $this->failedEntries / $this->totalEntries * 100) . PHP_EOL;
}