Skip to content

Commit

Permalink
chore: add script to check untranslated locales (#256)
Browse files Browse the repository at this point in the history
* chore: add script to check untranslated locales

* chore: update gitattributes and php-cs-fixer.dist.php

* chore: add --ansi

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: add new line

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: make one line

Ansi output does not look good on Windows so we can leave it as is.

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: change color

white on Windows is a "bold" white which doesn't look well with red.

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: make colored output

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: make one line

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: change color

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>

* chore: fix result code of the script

* chore: refactor getTestCaseClassname()

Co-authored-by: John Paul E. Balandan, CPA <51850998+paulbalandan@users.noreply.github.com>
  • Loading branch information
kenjis and paulbalandan committed Nov 20, 2021
1 parent 6ca8e76 commit 954e095
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Expand Up @@ -9,3 +9,6 @@ tests/ export-ignore
utils/ export-ignore
phpunit.xml.dist export-ignore
.php-cs-fixer.dist.php export-ignore

# development tools
bin/test
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Expand Up @@ -22,6 +22,7 @@
->append([
__FILE__,
'.github/scripts/continuous-integration',
'bin/test',
]);

$overrides = [];
Expand Down
78 changes: 78 additions & 0 deletions bin/test
@@ -0,0 +1,78 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

require __DIR__ . '/../vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php';

use CodeIgniter\CLI\CLI;
use Translations\Tests\AbstractTranslationTestCase;

$phpCsFixer = 'vendor/bin/php-cs-fixer';
$phpunit = 'vendor/bin/phpunit';

if (CLI::isWindows()) {
$phpCsFixer = strtr($phpCsFixer, '/', '\\');
$phpunit = strtr($phpunit, '/', '\\');
}

CLI::write('Running `composer update`...', 'black', 'green');
passthru('composer update --ansi');
CLI::write();

CLI::write('Fixing coding style...', 'black', 'green');
passthru("{$phpCsFixer} fix --verbose --diff");
CLI::write();

$testCase = new class () extends AbstractTranslationTestCase {
public function getTestCaseClassname(string $locale): string
{
$classname = array_flip(self::$locales)[$locale] ?? null;

if ($classname === null) {
CLI::write('Locale "' . $locale . '" not found.', 'light_gray', 'red');

exit(1);
}

$namespaces = explode('\\', $classname);

return end($namespaces);
}
};

if ($argc === 2) {
$locale = $argv[1];

$testClassname = $testCase->getTestCaseClassname($locale);

CLI::write('Running test...', 'black', 'green');
$command = "{$phpunit} --filter {$testClassname} --color=always";
CLI::write($command);
passthru($command, $resultCode);

exit($resultCode);
}

CLI::write(
'The following locales have untranslated items:',
'light_gray',
'red'
);
exec($phpunit, $output, $resultCode);

$untranslatedLocales = [];

foreach ($output as $line) {
$pattern = '/\A\d+\) Translations\\\\(.*)"(.+?)"/';
if (preg_match($pattern, $line, $matches) === 1) {
$locale = $matches[2];
$untranslatedLocales[$locale] = $locale;
}
}

ksort($untranslatedLocales);

foreach ($untranslatedLocales as $locale) {
CLI::write($locale);
}

exit($resultCode);

0 comments on commit 954e095

Please sign in to comment.