aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorGravatar Alexis Degrugillier <aledeg@users.noreply.github.com> 2022-10-20 17:42:47 -0400
committerGravatar GitHub <noreply@github.com> 2022-10-20 23:42:47 +0200
commit1f4e347cae51667e7cf5772aef55d274a39c8023 (patch)
tree86ba1032c30b581223a7131764d8384f4b566d88 /cli
parentd4181e098d93379c21251bd94d1397e16e56218a (diff)
Add tests on i18n classes (#4756)
Diffstat (limited to 'cli')
-rw-r--r--cli/i18n/I18nCompletionValidator.php8
-rw-r--r--cli/i18n/I18nFile.php11
-rw-r--r--cli/i18n/I18nUsageValidator.php6
-rwxr-xr-xcli/manipulate.translation.php2
4 files changed, 17 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;
}
diff --git a/cli/manipulate.translation.php b/cli/manipulate.translation.php
index 2b53b8606..801aa30b6 100755
--- a/cli/manipulate.translation.php
+++ b/cli/manipulate.translation.php
@@ -3,6 +3,8 @@
require_once __DIR__ . '/i18n/I18nData.php';
require_once __DIR__ . '/i18n/I18nFile.php';
+require_once __DIR__ . '/../constants.php';
+
$options = getopt("a:hk:l:o:rv:");