diff --git a/.gitignore b/.gitignore index 18dfb74..0f0313b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /vendor/ /.idea/ /bin/ -/3.2/ -/3.3/ +/4.0/ diff --git a/README.md b/README.md index 6b36133..ab906e2 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,44 @@ -# phpBB Translation Validator - master-dev +# phpBB Translation Validator -This console application allows you to validate [phpBB](https://www.phpbb.com) language packages. +With the help of this command line application you are able +to validate [phpBB](https://www.phpbb.com) language packs. +This application runs on your local machine and can be integrated +into a [GitHub](https://www.github.com) repository. -## Requirements +## πŸ“‹Requirements -This tool requires PHP 8.1 or above. +This tool requires PHP 8.1 or above. In addition it needs several +symfony and other packages, which need to be downloaded and installed with [Composer](https://getcomposer.org). -### Installation -Firstly, download the latest British English (`en`) [language pack from phpBB.com](http://www.phpbb.com/customise/db/translation/british_english/) as this is the default source language. Then clone this repository and download the dependencies: +## πŸ—οΈ Installation + +Clone this repository: git clone https://github.com/phpbb/phpbb-translation-validator.git + +Install the dependencies with Composer: + composer.phar install -For the easiest results, create a directory called `4.0` in the root of the Translation Validator. Upload the `en` language page into this directory, along with the languages you wish to test. Which leads e.g. to: +Create a directory called `4.0` in the root of the Translation Validator. Afterwards download +the [British English language pack](http://www.phpbb.com/customise/db/translation/british_english/) +and put its content into ``4.0/en/``. Do the same with the languages you wish to test. Which leads e.g. to: phpbb-translation-validator/4.0/en/ phpbb-translation-validator/4.0/de/ + phpbb-translation-validator/4.0/fr/ phpbb-translation-validator/translation.php -The simplest way to validate is to then run this command (the final argument is the language you wish to test and that has already been uploaded to the `3.2` directory; eg. `fr` for French): +## βš—οΈ Validate language packs + +The simplest way to validate this language packages, +is to open a command line tool in the validator directory. +Then run this command (the final argument is the language you wish to test and that has already been stored to the `4.0` directory; e.g. `fr` for French): php translation.php validate fr -There are more arguments that can be supplied. For example, suppose you wanted to have your `3.2` directory in a different location, you wanted to explicitly specify phpBB version 3.2 (default validation is against 3.3), you wanted to run in safe mode and you wanted to see all notices displayed - you would run this command: +There are more arguments that can be supplied. For example, suppose you wanted to have your `4.x` directory in a different location, you wanted to explicitly specify phpBB version 4.x (default validation is against 4.0), you wanted to run in safe mode and you wanted to see all notices displayed - you would run this command: php translation.php validate fr --package-dir=/path/to/your/4.0 @@ -31,15 +46,15 @@ There are more arguments that can be supplied. For example, suppose you wanted t --safe-mode --display-notices -The `--safe-mode` flag indicates that you want to parse files instead of directly including them. This is useful if you want to run validations on a web server. +The `--safe-mode` flag indicates that you want to parse files instead of directly including them. +This is useful if you want to run validations on a web server. -If you are missing the English language files for the official Viglink extension, they can be easily donwloaded using this command: +If you are missing the English language files for the official Viglink extension, +they can be easily donwloaded using this command: php translation.php download --files=phpbb-extensions/viglink --phpbb-version=4.0 -## Tests - -![GitHub Actions CI](https://github.com/phpbb/phpbb-translation-validator/actions/workflows/phpunit.yaml/badge.svg?branch=master) +## πŸ› οΈ Integration to your Repository In your project you can add phpBB Translation Validator as a dependency: @@ -53,18 +68,24 @@ Then add a `php vendor/bin/translation.php` call to your workflow. We use GitHub Actions as a continuous integration server and phpunit for our unit testing. +### 🏠 Local phpunit execution + To run the unit tests locally, use this command: php vendor/phpunit/phpunit/phpunit tests/ -## Contributing +## πŸ€– Tests + +![GitHub Actions CI](https://github.com/phpbb/phpbb-translation-validator/actions/workflows/phpunit.yaml/badge.svg?branch=master) + +## πŸ§‘β€πŸ’» Contributing -If you notice any problems with this application, please raise an issue at https://github.com/phpbb/phpbb-translation-validator/issues. +If you notice any problems with this application, please raise an issue at the [Github-Repository](https://github.com/phpbb/phpbb-translation-validator/issues). -To submit your own code contributions, please fork the project and submit a pull request at https://github.com/phpbb/phpbb-translation-validator/pulls. +To submit your own code contributions, please fork the project and submit a pull request at [Github-Repository](https://github.com/phpbb/phpbb-translation-validator/pulls). -When a new version is released, the version number will be updated in `composer.json` and `translation.php`. A new tag will be created and the package will become available at https://packagist.org/packages/phpbb/translation-validator. +When a new version is released, the version number will be updated in `composer.json` and `translation.php`. A new tag will be created and the package will become available at [Packagist](https://packagist.org/packages/phpbb/translation-validator). -## License +## πŸ“œ License -[GPLv2](license.txt) +[GNU General Public License v2](license.txt) diff --git a/src/Phpbb/TranslationValidator/Command/DownloadCommand.php b/src/Phpbb/TranslationValidator/Command/DownloadCommand.php index 9f7310a..00bf9f0 100644 --- a/src/Phpbb/TranslationValidator/Command/DownloadCommand.php +++ b/src/Phpbb/TranslationValidator/Command/DownloadCommand.php @@ -31,9 +31,8 @@ protected function configure() ->setName('download') ->setDescription('If you are missing important files, this tool can automatically download them for you.') ->addOption('files', null, InputOption::VALUE_REQUIRED, 'Which files do you want to download?', 'phpbb-extensions/viglink') - ->addOption('phpbb-version', null, InputOption::VALUE_OPTIONAL, 'The phpBB version you use to validate against', '3.3'); + ->addOption('phpbb-version', null, InputOption::VALUE_OPTIONAL, 'The phpBB version you use to validate against', '4.0'); } - protected function execute(InputInterface $input, OutputInterface $output) { $files = $input->getOption('files'); diff --git a/src/Phpbb/TranslationValidator/Command/ValidateCommand.php b/src/Phpbb/TranslationValidator/Command/ValidateCommand.php index e65bf8b..7aa1d38 100644 --- a/src/Phpbb/TranslationValidator/Command/ValidateCommand.php +++ b/src/Phpbb/TranslationValidator/Command/ValidateCommand.php @@ -25,7 +25,7 @@ protected function configure() ->setName('validate') ->setDescription('Run the validator on your language pack.') ->addArgument('origin-iso', InputArgument::REQUIRED, 'The ISO of the language to validate') - ->addOption('phpbb-version', null, InputOption::VALUE_OPTIONAL, 'The phpBB Version to validate against', '3.3') + ->addOption('phpbb-version', null, InputOption::VALUE_OPTIONAL, 'The phpBB Version to validate against', '4.0') ->addOption('source-iso', null, InputOption::VALUE_OPTIONAL, 'The ISO of the language to validate against', 'en') ->addOption('package-dir', null, InputOption::VALUE_OPTIONAL, 'The path to the directory with the language packages', null) ->addOption('language-dir', null, InputOption::VALUE_OPTIONAL, 'The path to the directory with the language folders', null) @@ -52,9 +52,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $displayNotices = $input->getOption('display-notices'); $safeMode = $input->getOption('safe-mode'); - if (!in_array($phpbbVersion, array('3.2', '3.3'))) + if ($phpbbVersion != '4.0') { - throw new \RuntimeException('Invalid phpbb-version, allowed versions: 3.2 and 3.3'); + throw new \RuntimeException('Invalid phpbb-version, allowed versions: 4.0'); } $output = new Output($output, $debug); diff --git a/src/Phpbb/TranslationValidator/Validator/FileListValidator.php b/src/Phpbb/TranslationValidator/Validator/FileListValidator.php index b4ce3c0..14036c1 100644 --- a/src/Phpbb/TranslationValidator/Validator/FileListValidator.php +++ b/src/Phpbb/TranslationValidator/Validator/FileListValidator.php @@ -137,20 +137,21 @@ public function validate() $sourceFiles[] = $this->sourceLanguagePath . 'LICENSE'; $sourceFiles = array_unique($sourceFiles); - // Get $lang['direction'] of translation to allow additional rtl-files for rtl-translations - $filePath = $this->originPath . '/' . $this->originLanguagePath . 'common.php'; + // Get extra->direction from composer.json to allow additional rtl-files for rtl-translations + $filePath = $this->originPath . '/' . $this->originLanguagePath . 'composer.json'; + // Safe mode for safe execution on a server if ($this->safeMode) { - $lang = ValidatorRunner::langParser($filePath); + $jsonContent = self::langParser($filePath); } - else { - include($filePath); + $fileContents = (string) file_get_contents($filePath); + $jsonContent = json_decode($fileContents, true); } - $this->direction = $lang['DIRECTION']; + $this->direction = $jsonContent['extra']['direction']; // Throw error, if invalid direction is used if (!in_array($this->direction, array('rtl', 'ltr'))) { @@ -159,7 +160,6 @@ public function validate() $originFiles = $this->getFileList($this->originPath); - $missingSubsilver2Files = $availableSubsilver2Files = array(); $validFiles = array(); foreach ($sourceFiles as $sourceFile) { @@ -194,10 +194,6 @@ public function validate() { $level = Output::NOTICE; } - else if ($this->phpbbVersion === '3.2' && strpos($origin_file, 'styles/subsilver2/') === 0) - { - $level = Output::FATAL; - } else if (in_array(substr($origin_file, -4), array('.gif', '.png')) && $this->direction === 'rtl') { $level = Output::WARNING; diff --git a/src/Phpbb/TranslationValidator/Validator/FileValidator.php b/src/Phpbb/TranslationValidator/Validator/FileValidator.php index 784f275..9a49c15 100644 --- a/src/Phpbb/TranslationValidator/Validator/FileValidator.php +++ b/src/Phpbb/TranslationValidator/Validator/FileValidator.php @@ -119,6 +119,47 @@ class FileValidator '', // Allow empty strings ]; + /** @var array List from https://developers.cloudflare.com/turnstile/reference/supported-languages/ */ + private $reTurnstilesLanguages = [ + 'ar', + 'bg', + 'zh', + 'hr', + 'cs', + 'da', + 'nl', + 'en', + 'fa', + 'fi', + 'fr', + 'de', + 'el', + 'he', + 'hi', + 'hu', + 'id', + 'it', + 'ja', + 'ko', + 'lt', + 'ms', + 'nb', + 'pl', + 'pt', + 'ro', + 'ru', + 'sr', + 'sk', + 'sl', + 'es', + 'sv', + 'tl', + 'th', + 'tr', + 'uk', + 'vi', + '', // Allow empty strings + ]; /** * @param InputInterface $input * @param OutputInterface $output @@ -227,6 +268,17 @@ public function setSafeMode($safeMode) return $this; } + /** + * Open the composer.json of the language pack and + * save it to an array, accessible for the following functions + */ + public function openComposerJson($originFile) + { + $fileContents = (string) file_get_contents($this->originPath . '/' . $originFile); + + return json_decode($fileContents, true); + } + /** * Decides which validation function to use * @@ -260,9 +312,10 @@ public function validate($sourceFile, $originFile) { $this->validateLicenseFile($originFile); } - else if ($originFile === $this->originLanguagePath . 'iso.txt') + else if ($originFile === $this->originLanguagePath . 'composer.json') { - $this->validateIsoFile($originFile); + $this->validateJsonFile($originFile); + $this->validateCaptchaValues($originFile); } else if (substr($originFile, -4) === '.css') { @@ -361,32 +414,10 @@ public function validateLangFile($sourceFile, $originFile) $this->output->addMessage(Output::FATAL, 'Must not contain key: ' . $validateLangKey, $originFile); } } - - // Check reCaptcha file - if ($originFile === $this->originLanguagePath . 'captcha_recaptcha.php') - { - $this->validateReCaptchaValue($originFile, $validate); - } } /** - * Check that the reCaptcha key provided is allowed - * @param $originFile - * @param array $validate - */ - public function validateReCaptchaValue($originFile, $validate) - { - // The key 'RECAPTCHA_LANG' must match the list provided by Google, or be left empty - // If any other key is used, we will show an error - if (array_key_exists('RECAPTCHA_LANG', $validate) && !in_array($validate['RECAPTCHA_LANG'], $this->reCaptchaLanguages)) - { - // The supplied value doesn't match the allowed values - $this->output->addMessage(Output::ERROR, 'reCaptcha must match a language/country code on https://developers.google.com/recaptcha/docs/language - if no code exists for your language you can use "en" or leave the string empty', $originFile, 'RECAPTCHA_LANG'); - } - } - - /** - * Validates a email .txt file + * Validates an email .txt file * * Emails must have a subject when the source file has one, otherwise must not have one. * Emails must have a signature when the source file has one, otherwise must not have one. @@ -521,26 +552,152 @@ public function validateIndexFile($originFile) } /** - * Validates the iso.txt file + * Validates the composer.json file * - * Should only contain 3 lines: - * 1. English name of the language - * 2. Native name of the language - * 3. Line with information about the author + * Should be valid and contain the necessary information: + * Mandatory: + * name, description, type, version, homepage, license + * Authors: name (optional: email and homepage) + * Extra: language-iso, english-name, local-name, + * phpbb-version, direction, user-lang, plural-rule + * Optional: + * Support: urls to: forum, wiki, issues etc * * @param string $originFile File to validate * @return null */ - public function validateIsoFile($originFile) + public function validateJsonFile($originFile) { - $fileContents = (string) file_get_contents($this->originPath . '/' . $originFile); - $isoFile = explode("\n", $fileContents); - - if (sizeof($isoFile) != 3) - { - $this->output->addMessage(Output::FATAL, 'Must contain exactly 3 lines: 1. English name, 2. Native name, 3. Author information', $originFile); - } - } + $jsonContent = $this->openComposerJson($originFile); + + if (!str_starts_with($jsonContent['name'], 'phpbb/phpbb-language-')) + { + $this->output->addMessage(Output::FATAL, 'Name should start with phpbb/phpbb-language- followed by the language iso code', $originFile); + } + // Check for an existing description + if (!array_key_exists('description', $jsonContent) || $jsonContent['description'] == '') + { + $this->output->addMessage(Output::FATAL, 'Description is missing', $originFile); + } + // Check if the description contains only words and punctuation, not URLs. + elseif (preg_match('/\b(?:www|https)\b|(?:\.[a-z]{2,})/i', $jsonContent['description'])) + { + $this->output->addMessage(Output::ERROR, 'The description should only contain words - no URLs.', $originFile); + } + // Check if the type is correctly defined + if ($jsonContent['type'] != 'phpbb-language') + { + $this->output->addMessage(Output::FATAL, 'Type must be exactly: "phpbb-language"', $originFile); + } + // Check if there is a valid version definition + if (!array_key_exists('version', $jsonContent)) + { + $this->output->addMessage(Output::FATAL, 'Language pack needs a version definition.', $originFile); + } + elseif ($jsonContent['version'] == '') + { + $this->output->addMessage(Output::FATAL, 'The defined version should not be empty.', $originFile); + } + elseif (!preg_match('/^(\d+\.)?(\d+\.)?(\*|\d+)$/', $jsonContent['version'])) + { + $this->output->addMessage(Output::ERROR, 'The defined version is in the wrong format.', $originFile); + } + // Homepage should be at least an empty string + if (!preg_match('/(?:https?:\/\/|www\.)[^\s]+|(?:\b[a-z0-9-]+\.(?:com|net|org|info|io|co|biz|me|xyz|ai|app|dev|tech|tv|us|uk|de|fr|ru|jp|cn|in)\b)/i', $jsonContent['homepage']) && $jsonContent['homepage'] != '') + { + $this->output->addMessage(Output::ERROR, 'The homepage value allows only URLs or can be left empty.', $originFile); + } + // Check for the correct license value + if ($jsonContent['license'] != 'GPL-2.0-only') + { + $this->output->addMessage(Output::FATAL, 'The license value has to be "GPL-2.0-only"', $originFile); + } + // Check for the authors + if (!array_key_exists('authors', $jsonContent)) + { + $this->output->addMessage(Output::ERROR, 'The authors value is missing.', $originFile); + } + // Check for support, authors should at least give one contact option! + if (!array_key_exists('support', $jsonContent)) + { + $this->output->addMessage(Output::ERROR, 'The support value is missing.', $originFile); + } + elseif (count ($jsonContent['support']) < 1) + { + $this->output->addMessage(Output::ERROR, 'The support category has no values. Please provide at least one contact option e.g. forum or email.', $originFile); + } + // Check for the extra-section + if (!array_key_exists('extra', $jsonContent)) + { + $this->output->addMessage(Output::FATAL, 'The extra section is missing.', $originFile); + } + // language-iso must be valid + if (!preg_match('/^(?:[a-z]*_?){0,2}[a-z]*$/', $jsonContent['extra']['language-iso'])) + { + $this->output->addMessage(Output::FATAL, 'The language-iso should only contain small letters from a to z and maximum two underscores.', $originFile); + } + elseif ($jsonContent['extra']['language-iso'] != $this->originIso) + { + $this->output->addMessage(Output::FATAL, 'Language iso is not valid', $originFile); + } + // Check for english name + if ($jsonContent['extra']['english-name'] == '' || !preg_match('/^[a-zA-Z\s]+$/', $jsonContent['extra']['english-name'])) + { + $this->output->addMessage(Output::ERROR, 'The english-name value should only contain letters aA-zZ and spaces.', $originFile); + } + // Check for local name + if ($jsonContent['extra']['local-name'] == '') + { + $this->output->addMessage(Output::ERROR, 'The local-name value should not be empty.', $originFile); + } + // Check for valid phpBB-Version, we accept: 4.0.0, 4.0.0-a1 or 4.0.0-b1 or 4.0.0-RC1 + if (!preg_match('/^\d+\.\d+\.\d+(-(?:a|b|RC)\d+)?$/', $jsonContent['extra']['phpbb-version']) || $jsonContent['extra']['phpbb-version'] == '' ) + { + $this->output->addMessage(Output::FATAL, 'The phpbb-version value should not be empty and contain a valid version number.', $originFile); + } + // Check for valid direction + $textDirection = $jsonContent['extra']['direction']; + if (!in_array($textDirection, array('ltr', 'rtl'))) + { + $this->output->addMessage(Output::FATAL, 'The direction can only be rtl or ltr.', $originFile); + } + // Check for user-lang: en-gb + if (!isset($jsonContent['extra']['user-lang']) || $jsonContent['extra']['user-lang'] == '') + { + $this->output->addMessage(Output::FATAL, 'The user-lang must be defined.', $originFile); + } + // Check for plural-rule + if (!preg_match('/^(?:[0-9]|1[0-5])$/', $jsonContent['extra']['plural-rule'])) + { + $this->output->addMessage(Output::FATAL, 'Plural rules does not have a valid value.', $originFile); + } + } + + /** + * Check that the reCaptcha and Turnstile key provided is allowed + * @param $originFile + */ + public function validateCaptchaValues($originFile, $optParams = '') + { + $jsonContent = $this->openComposerJson($originFile); + + if ($optParams != '') + { + $jsonContent['extra']['recaptcha-lang'] = $optParams; + } + // The key 'RECAPTCHA_LANG' must match the list provided by Google, or be left empty + // Check for valid recaptcha-lang: en-GB + if (!in_array($jsonContent['extra']['recaptcha-lang'], $this->reCaptchaLanguages)) + { + $this->output->addMessage(Output::ERROR, 'reCaptcha must match a language/country code on https://developers.google.com/recaptcha/docs/language - if no code exists for your language you can use "en".', $originFile); + } + // Check for valid turnstile-lang: en + // (should be in: https://developers.cloudflare.com/turnstile/reference/supported-languages/ ) + if (!in_array($jsonContent['extra']['turnstile-lang'], $this->reTurnstilesLanguages)) + { + $this->output->addMessage(Output::ERROR, 'Turnstile must match a 2-digit-language code from https://developers.cloudflare.com/turnstile/reference/supported-languages/ - if no code exists for your language you can use "en".', $originFile); + } + } /** * Validates whether a file checks for the IN_PHPBB constant diff --git a/src/Phpbb/TranslationValidator/Validator/LangKeyValidator.php b/src/Phpbb/TranslationValidator/Validator/LangKeyValidator.php index eff3492..9c8a9f3 100644 --- a/src/Phpbb/TranslationValidator/Validator/LangKeyValidator.php +++ b/src/Phpbb/TranslationValidator/Validator/LangKeyValidator.php @@ -619,10 +619,7 @@ public function validateHtml($file, $key, $sourceString, $originString) 'SUPPORT_BODY', 'UPDATE_INSTALLATION_EXPLAIN', 'OVERVIEW_BODY', - )) || ($this->phpbbVersion == '3.2' && ($this->originLanguagePath . 'ucp.php' === $file && in_array($key, array( //Check for 3.2 - 'TERMS_OF_USE_CONTENT', - 'PRIVACY_POLICY', - ))))) + ))) { $sourceString = '

' . $sourceString . '

'; $originString = '

' . $originString . '

'; @@ -729,11 +726,6 @@ public function validateHtml($file, $key, $sourceString, $originString) } } - if ($this->originLanguagePath . 'ucp.php' === $file && in_array($key, array('TERMS_OF_USE_CONTENT', 'PRIVACY_POLICY')) && ($this->phpbbVersion != '3.2')) - { - $level = Output::ERROR; - } - $this->output->addMessage($level, 'String is using additional html: ' . $possibleHtml, $file, $key); } } diff --git a/src/Phpbb/TranslationValidator/Validator/ValidatorRunner.php b/src/Phpbb/TranslationValidator/Validator/ValidatorRunner.php index 9bbef53..30b0c30 100644 --- a/src/Phpbb/TranslationValidator/Validator/ValidatorRunner.php +++ b/src/Phpbb/TranslationValidator/Validator/ValidatorRunner.php @@ -228,36 +228,37 @@ protected function printErrorLevel(Output $output) } /** - * Try to find the plural rule for the language + * Try to find the plural rule for the language in composer.json * @return int */ - protected function guessPluralRule() + protected function guessPluralRule(): int { - $filePath = $this->originPath . '/' . $this->originLanguagePath . 'common.php'; - - if (file_exists($filePath)) - { - if ($this->safeMode) - { - $lang = self::langParser($filePath); - } - - else - { - include($filePath); - } - - if (!isset($lang['PLURAL_RULE'])) - { - $this->output->writelnIfDebug("No plural rule set, falling back to plural rule #1"); - } - } + $filePath = $this->originPath . '/' . $this->originLanguagePath . 'composer.json'; + + if (file_exists($filePath)) + { + // Safe mode for safe execution on a server + if ($this->safeMode) + { + $jsonContent = self::langParser($filePath); + } + else + { + $fileContents = (string) file_get_contents($filePath); + $jsonContent = json_decode($fileContents, true); + } + + if (!isset($jsonContent['extra']['plural-rule'])) + { + $this->output->writelnIfDebug("No plural rule set, falling back to plural rule #1"); + } + } else { - $this->output->writelnIfDebug("Could not find common.php, falling back to plural rule #1"); + $this->output->writelnIfDebug("Could not find composer.json, falling back to plural rule #1"); } - return isset($lang['PLURAL_RULE']) ? $lang['PLURAL_RULE'] : 1; + return $jsonContent['extra']['plural-rule'] ?? 1; } /** @@ -278,7 +279,7 @@ public static function arrayParser($file) * @param string $relativePath * @return array */ - public static function langParser($filePath, $relativePath = '') + public static function langParser($filePath, string $relativePath = '') { $lang = []; $parsed = self::arrayParser($relativePath . $filePath); diff --git a/tests/FileListValidator/FileListTest.php b/tests/FileListValidator/FileListTest.php index 2000958..d1eda44 100644 --- a/tests/FileListValidator/FileListTest.php +++ b/tests/FileListValidator/FileListTest.php @@ -26,7 +26,7 @@ public function validateFileListData() { return array( array( - '3.2', + '4.0', array( Output::FATAL . '-Missing required file-missing.php-', Output::FATAL . '-Missing required file-missing.txt-', diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/common.php b/tests/FileListValidator/fixtures/3.2/origin/language/origin/common.php deleted file mode 100644 index 9175202..0000000 --- a/tests/FileListValidator/fixtures/3.2/origin/language/origin/common.php +++ /dev/null @@ -1,37 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -if (empty($lang) || !is_array($lang)) -{ - $lang = array(); -} - -// DEVELOPERS PLEASE NOTE -// -// All language files should use UTF-8 as their encoding and the files must not contain a BOM. -// -// Placeholders can now contain order information, e.g. instead of -// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows -// translators to re-order the output of data while ensuring it remains correct -// -// You do not need this where single placeholders are used, e.g. 'Message %d' is fine -// equally where a string contains only two placeholders which are used to wrap text -// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine -// -// Some characters you may want to copy&paste: -// ’ Β» β€œ ” … -// - -$lang = array_merge($lang, array( - 'DIRECTION' => 'ltr', -)); diff --git a/tests/FileListValidator/fixtures/3.2/source/language/source/common.php b/tests/FileListValidator/fixtures/3.2/source/language/source/common.php deleted file mode 100644 index 9175202..0000000 --- a/tests/FileListValidator/fixtures/3.2/source/language/source/common.php +++ /dev/null @@ -1,37 +0,0 @@ - -* @license GNU General Public License, version 2 (GPL-2.0) -* -* For full copyright and license information, please see -* the docs/CREDITS.txt file. -* -*/ - -if (empty($lang) || !is_array($lang)) -{ - $lang = array(); -} - -// DEVELOPERS PLEASE NOTE -// -// All language files should use UTF-8 as their encoding and the files must not contain a BOM. -// -// Placeholders can now contain order information, e.g. instead of -// 'Page %s of %s' you can (and should) write 'Page %1$s of %2$s', this allows -// translators to re-order the output of data while ensuring it remains correct -// -// You do not need this where single placeholders are used, e.g. 'Message %d' is fine -// equally where a string contains only two placeholders which are used to wrap text -// in a url you again do not need to specify an order e.g., 'Click %sHERE%s' is fine -// -// Some characters you may want to copy&paste: -// ’ Β» β€œ ” … -// - -$lang = array_merge($lang, array( - 'DIRECTION' => 'ltr', -)); diff --git a/tests/FileListValidator/fixtures/3.2/origin/additional.php b/tests/FileListValidator/fixtures/4.0/origin/additional.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/additional.php rename to tests/FileListValidator/fixtures/4.0/origin/additional.php diff --git a/tests/FileListValidator/fixtures/3.2/origin/additional.txt b/tests/FileListValidator/fixtures/4.0/origin/additional.txt similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/additional.txt rename to tests/FileListValidator/fixtures/4.0/origin/additional.txt diff --git a/tests/FileListValidator/fixtures/3.2/origin/file.php b/tests/FileListValidator/fixtures/4.0/origin/file.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/file.php rename to tests/FileListValidator/fixtures/4.0/origin/file.php diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/AUTHORS b/tests/FileListValidator/fixtures/4.0/origin/language/origin/AUTHORS similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/AUTHORS rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/AUTHORS diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/AUTHORS.md b/tests/FileListValidator/fixtures/4.0/origin/language/origin/AUTHORS.md similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/AUTHORS.md rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/AUTHORS.md diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/CHANGELOG b/tests/FileListValidator/fixtures/4.0/origin/language/origin/CHANGELOG similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/CHANGELOG rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/CHANGELOG diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/CHANGELOG.md b/tests/FileListValidator/fixtures/4.0/origin/language/origin/CHANGELOG.md similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/CHANGELOG.md rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/CHANGELOG.md diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/README b/tests/FileListValidator/fixtures/4.0/origin/language/origin/README similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/README rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/README diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/README.md b/tests/FileListValidator/fixtures/4.0/origin/language/origin/README.md similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/README.md rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/README.md diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/VERSION b/tests/FileListValidator/fixtures/4.0/origin/language/origin/VERSION similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/VERSION rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/VERSION diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/VERSION.md b/tests/FileListValidator/fixtures/4.0/origin/language/origin/VERSION.md similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/VERSION.md rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/VERSION.md diff --git a/tests/FileListValidator/fixtures/4.0/origin/language/origin/composer.json b/tests/FileListValidator/fixtures/4.0/origin/language/origin/composer.json new file mode 100644 index 0000000..404e01b --- /dev/null +++ b/tests/FileListValidator/fixtures/4.0/origin/language/origin/composer.json @@ -0,0 +1,5 @@ +{ + "extra": { + "direction": "ltr" + } +} diff --git a/tests/FileListValidator/fixtures/3.2/origin/language/origin/index.htm b/tests/FileListValidator/fixtures/4.0/origin/language/origin/index.htm similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/language/origin/index.htm rename to tests/FileListValidator/fixtures/4.0/origin/language/origin/index.htm diff --git a/tests/FileListValidator/fixtures/3.2/origin/subdir/additional.php b/tests/FileListValidator/fixtures/4.0/origin/subdir/additional.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/subdir/additional.php rename to tests/FileListValidator/fixtures/4.0/origin/subdir/additional.php diff --git a/tests/FileListValidator/fixtures/3.2/origin/subdir/file.php b/tests/FileListValidator/fixtures/4.0/origin/subdir/file.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/origin/subdir/file.php rename to tests/FileListValidator/fixtures/4.0/origin/subdir/file.php diff --git a/tests/FileListValidator/fixtures/3.2/source/file.php b/tests/FileListValidator/fixtures/4.0/source/file.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/source/file.php rename to tests/FileListValidator/fixtures/4.0/source/file.php diff --git a/tests/FileListValidator/fixtures/4.0/source/language/source/composer.json b/tests/FileListValidator/fixtures/4.0/source/language/source/composer.json new file mode 100644 index 0000000..404e01b --- /dev/null +++ b/tests/FileListValidator/fixtures/4.0/source/language/source/composer.json @@ -0,0 +1,5 @@ +{ + "extra": { + "direction": "ltr" + } +} diff --git a/tests/FileListValidator/fixtures/3.2/source/missing.php b/tests/FileListValidator/fixtures/4.0/source/missing.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/source/missing.php rename to tests/FileListValidator/fixtures/4.0/source/missing.php diff --git a/tests/FileListValidator/fixtures/3.2/source/missing.txt b/tests/FileListValidator/fixtures/4.0/source/missing.txt similarity index 100% rename from tests/FileListValidator/fixtures/3.2/source/missing.txt rename to tests/FileListValidator/fixtures/4.0/source/missing.txt diff --git a/tests/FileListValidator/fixtures/3.2/source/subdir/file.php b/tests/FileListValidator/fixtures/4.0/source/subdir/file.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/source/subdir/file.php rename to tests/FileListValidator/fixtures/4.0/source/subdir/file.php diff --git a/tests/FileListValidator/fixtures/3.2/source/subdir/missing.php b/tests/FileListValidator/fixtures/4.0/source/subdir/missing.php similarity index 100% rename from tests/FileListValidator/fixtures/3.2/source/subdir/missing.php rename to tests/FileListValidator/fixtures/4.0/source/subdir/missing.php diff --git a/tests/FileValidator/ValidateIsoTest.php b/tests/FileValidator/ValidateIsoTest.php deleted file mode 100644 index 7e4f3f3..0000000 --- a/tests/FileValidator/ValidateIsoTest.php +++ /dev/null @@ -1,36 +0,0 @@ -validator->validateIsoFile($file); - $this->assertOutputMessages($expected); - } -} diff --git a/tests/FileValidator/ValidateLangTest.php b/tests/FileValidator/ValidateLangTest.php index cc9316b..dd9b1e1 100644 --- a/tests/FileValidator/ValidateLangTest.php +++ b/tests/FileValidator/ValidateLangTest.php @@ -41,21 +41,21 @@ public function testValidateLangFile($file, $expected) /** * Test the reCaptcha checks */ - public function testValidateLangReCaptcha() + public function testValidateLangCaptchas() { // Failure - as we supply a key that isn't valid - $reCaptchaLanguage = ['RECAPTCHA_LANG' => 'incorrect']; - $this->validator->validateReCaptchaValue('', $reCaptchaLanguage); + $reCaptchaLanguage = 'incorrect'; + $this->validator->validateCaptchaValues('', $reCaptchaLanguage); $output = $this->output->getMessages(); - $expected = Output::ERROR . '-reCaptcha must match a language/country code on https://developers.google.com/recaptcha/docs/language - if no code exists for your language you can use "en" or leave the string empty--RECAPTCHA_LANG'; + $expected = Output::ERROR . '-reCaptcha must match a language/country code on https://developers.google.com/recaptcha/docs/language - if no code exists for your language you can use "en".--'; $this->assertEquals($this->output->getMessageCount(Output::ERROR), 1); $this->assertEquals($output[0], $expected); // Pass - as 'en' is valid - $reCaptchaLanguage['RECAPTCHA_LANG'] = 'en'; - $this->validator->validateReCaptchaValue('', $reCaptchaLanguage); + $reCaptchaLanguage = 'en'; + $this->validator->validateCaptchaValues('', $reCaptchaLanguage); $this->assertEquals($this->output->getMessageCount(Output::ERROR), 1); // Shouldn't change in size as no error added } diff --git a/tests/FileValidator/ValidateNoPhpClosingTagTest.php b/tests/FileValidator/ValidateNoPhpClosingTagTest.php index 60f73d7..3a79c1b 100644 --- a/tests/FileValidator/ValidateNoPhpClosingTagTest.php +++ b/tests/FileValidator/ValidateNoPhpClosingTagTest.php @@ -15,7 +15,7 @@ class ValidateNoPhpClosingTagTest extends TestBase public function validateNoPhpClosingTagData() { return array( - array('3.2', 'nophpclosingtag/shortarraysyntax.php', array()), + array('4.0', 'nophpclosingtag/shortarraysyntax.php', array()), ); } diff --git a/tests/LangKeyValidator/TestBase.php b/tests/LangKeyValidator/TestBase.php index 7aa799c..f7bc0f1 100644 --- a/tests/LangKeyValidator/TestBase.php +++ b/tests/LangKeyValidator/TestBase.php @@ -20,7 +20,7 @@ public function setUp(): void $this->validator = new \Phpbb\TranslationValidator\Validator\LangKeyValidator($this->getMockBuilder('Symfony\Component\Console\Input\InputInterface')->getMock(), $this->output); $this->validator->setOrigin('origin', dirname(__FILE__) . '/fixtures/origin', 'language/origin/') ->setSource('source', dirname(__FILE__) . '/fixtures/source', 'language/source/') - ->setPhpbbVersion('3.2') + ->setPhpbbVersion('4.0') ->setPluralRule(1); } } diff --git a/translation.php b/translation.php index 1b8b7a5..f160b62 100644 --- a/translation.php +++ b/translation.php @@ -8,7 +8,7 @@ * */ -const TRANSLATION_VALIDATOR_VERSION = '1.6.0'; +const TRANSLATION_VALIDATOR_VERSION = '2.0.0-dev'; require 'vendor/autoload.php';