diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 8447c45..2a67b1b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -28,3 +28,11 @@ jobs: with: php_versions: '["8.3"]' bedita_version: '5' + coverage_min_percentage: 99 + + unit-6: + uses: bedita/github-workflows/.github/workflows/php-unit.yml@v2 + with: + php_versions: '["8.4"]' + bedita_version: '6' + coverage_min_percentage: 99 diff --git a/README.md b/README.md index c234f33..4ccff0f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# I18n plugin for BEdita4 & CakePHP +# I18n plugin for BEdita & CakePHP [![Github Actions](https://github.com/bedita/i18n/workflows/php/badge.svg)](https://github.com/bedita/i18n/actions?query=workflow%3Aphp) [![codecov](https://codecov.io/gh/bedita/i18n/branch/master/graph/badge.svg)](https://codecov.io/gh/bedita/i18n) @@ -9,7 +9,7 @@ ## Installation -You can install this BEdita4/CakePHP plugin using [composer](http://getcomposer.org) like this: +You can install this BEdita/CakePHP plugin using [composer](http://getcomposer.org) like this: ```bash composer require bedita/i18n diff --git a/composer.json b/composer.json index 802d8e1..053f696 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "bedita/i18n", - "description": "Internationalization plugin for BEdita 4 & CakePHP", + "description": "Internationalization plugin for BEdita & CakePHP", "type": "cakephp-plugin", "license": "LGPL-3.0-or-later", "support": { @@ -41,10 +41,16 @@ "@test", "@cs-check" ], + "cs-setup": [ + "vendor/bin/phpcs --config-set installed_paths vendor/cakephp/cakephp-codesniffer", + "vendor/bin/phpcs --config-set default_standard CakePHP", + "vendor/bin/phpcs --config-set colors 1" + ], + "cs-check": "vendor/bin/phpcs --colors -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", + "cs-fix": "vendor/bin/phpcbf --colors --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests", "stan": "vendor/bin/phpstan analyse", - "cs-check": "vendor/bin/phpcs", - "cs-fix": "vendor/bin/phpcbf", "test": "vendor/bin/phpunit --colors=always", + "coverage": "vendor/bin/phpunit --colors=always --coverage-html coverage", "update-dev": [ "@composer update", "@cs-setup" diff --git a/src/Command/GettextCommand.php b/src/Command/GettextCommand.php index 0d98b22..b347523 100644 --- a/src/Command/GettextCommand.php +++ b/src/Command/GettextCommand.php @@ -106,7 +106,8 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar 'boolean' => true, ]) ->addOption('locales', [ - 'help' => 'Comma separated list of locales to generate. Leave empty to use configuration `I18n.locales`', + 'help' => 'Comma separated list of locales to generate. ' . + 'Leave empty to use configuration `I18n.locales`', 'short' => 'l', 'default' => implode(',', array_keys((array)Configure::read('I18n.locales'))), ]); @@ -125,7 +126,8 @@ public function execute(Arguments $args, ConsoleIo $io) $resCmd = []; exec('which msgmerge 2>&1', $resCmd); - $msg = empty($resCmd[0]) ? 'ERROR: msgmerge not available. Please install gettext utilities.' : 'OK: msgmerge found'; + $errorMsg = 'ERROR: msgmerge not available. Please install gettext utilities.'; + $msg = empty($resCmd[0]) ? $errorMsg : 'OK: msgmerge found'; $method = empty($resCmd[0]) ? 'abort' : 'out'; $io->{$method}($msg); diff --git a/src/Filesystem/Gettext.php b/src/Filesystem/Gettext.php index 21a147e..a3dae27 100644 --- a/src/Filesystem/Gettext.php +++ b/src/Filesystem/Gettext.php @@ -67,7 +67,7 @@ public static function header(string $type = 'po'): string $result = sprintf('msgid ""%smsgstr ""%s', "\n", "\n"); $contents = [ 'po' => [ - 'Project-Id-Version' => 'BEdita 4', + 'Project-Id-Version' => 'BEdita', 'POT-Creation-Date' => FrozenTime::now()->format('Y-m-d H:i:s'), 'PO-Revision-Date' => '', 'Last-Translator' => '', @@ -79,7 +79,7 @@ public static function header(string $type = 'po'): string 'Content-Type' => 'text/plain; charset=utf-8', ], 'pot' => [ - 'Project-Id-Version' => 'BEdita 4', + 'Project-Id-Version' => 'BEdita', 'POT-Creation-Date' => FrozenTime::now()->format('Y-m-d H:i:s'), 'MIME-Version' => '1.0', 'Content-Transfer-Encoding' => '8bit', @@ -102,6 +102,8 @@ public static function header(string $type = 'po'): string * - info: array of info messages * - updated: boolean, true if file has been updated * + * @param string $localePath Locale path + * @param array $translations Translations * @return array */ public static function writeMasterPot(string $localePath, array $translations): array @@ -145,6 +147,9 @@ public static function writeMasterPot(string $localePath, array $translations): * * - info: array of info messages * + * @param array $locales Locales + * @param string $localePath Locale path + * @param array $translations Translations * @return array */ public static function writePoFiles(array $locales, string $localePath, array &$translations): array diff --git a/src/Filesystem/Paths.php b/src/Filesystem/Paths.php index 0474e39..a003d53 100644 --- a/src/Filesystem/Paths.php +++ b/src/Filesystem/Paths.php @@ -107,7 +107,9 @@ public static function setupPlugins(array &$templatePaths, string &$localePath): $acc, array_filter( (array)scandir($path), - fn ($file) => is_string($file) && !in_array($file, ['.', '..']) && Plugin::getCollection()->has($file) + fn ($file) => is_string($file) + && !in_array($file, ['.', '..']) + && Plugin::getCollection()->has($file) ) ), [] diff --git a/tests/TestCase/Filesystem/GettextTest.php b/tests/TestCase/Filesystem/GettextTest.php index 686b97a..e9b9bfb 100644 --- a/tests/TestCase/Filesystem/GettextTest.php +++ b/tests/TestCase/Filesystem/GettextTest.php @@ -41,7 +41,7 @@ public function testHeader(): void $actual = Gettext::header(); static::assertTrue(strpos($actual, 'msgid ""') === 0); static::assertTrue(strpos($actual, 'msgstr ""') > 0); - static::assertTrue(strpos($actual, 'Project-Id-Version: BEdita 4') > 0); + static::assertTrue(strpos($actual, 'Project-Id-Version: BEdita') > 0); static::assertTrue(strpos($actual, 'Language-Team: BEdita I18N & I10N Team') > 0); static::assertTrue(strpos($actual, 'MIME-Version: 1.0') > 0); static::assertTrue(strpos($actual, 'Content-Transfer-Encoding: 8bit') > 0); diff --git a/tests/test_dir/messages.po b/tests/test_dir/messages.po index 5607a07..ead01c2 100644 --- a/tests/test_dir/messages.po +++ b/tests/test_dir/messages.po @@ -1,6 +1,6 @@ msgid "" msgstr "" -"Project-Id-Version: BEdita 4 \n" +"Project-Id-Version: BEdita \n" "POT-Creation-Date: 2023-06-20 11:06:15 \n" "PO-Revision-Date: \n" "Last-Translator: \n" diff --git a/tests/test_dir/sample.php b/tests/test_dir/sample.php index 852759e..ae4c9f0 100644 --- a/tests/test_dir/sample.php +++ b/tests/test_dir/sample.php @@ -1,3 +1,4 @@