diff --git a/composer.json b/composer.json index 88762ea4d5a732116fdb10e8debeefc074373d03..178e5092b0ee1b3445f51c430b2b28e9aa5fac08 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,8 @@ "ext-pcre": "*", "ext-SPL": "*", "ext-zlib": "*", - "gettext/gettext": "v4.x-dev#3e7460f8d9c90174824e3f39240bd578bb3d376a", + "gettext/gettext": "^5.6.1", + "gettext/translator": "^1.0.1", "phpmailer/phpmailer": "^6.5", "simplesamlphp/assert": "^0.2.11", "simplesamlphp/saml2": "^4.5", diff --git a/composer.lock b/composer.lock index 8bd51e811172c71dac8e261d868e08a2e610590b..f3ff51e61368441c38a01e98a15fae9afa78ed34 100644 --- a/composer.lock +++ b/composer.lock @@ -4,39 +4,32 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "499ed983a7e8abed35ed5ab324abc681", + "content-hash": "84c8e5d462b13ed3f1436c1c9d9b5231", "packages": [ { "name": "gettext/gettext", - "version": "4.x-dev", + "version": "v5.6.1", "source": { "type": "git", "url": "https://github.com/php-gettext/Gettext.git", - "reference": "3e7460f8d9c90174824e3f39240bd578bb3d376a" + "reference": "017e249601d32b9a88c2eb4c10eac89bf582a7d3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-gettext/Gettext/zipball/3e7460f8d9c90174824e3f39240bd578bb3d376a", - "reference": "3e7460f8d9c90174824e3f39240bd578bb3d376a", + "url": "https://api.github.com/repos/php-gettext/Gettext/zipball/017e249601d32b9a88c2eb4c10eac89bf582a7d3", + "reference": "017e249601d32b9a88c2eb4c10eac89bf582a7d3", "shasum": "" }, "require": { "gettext/languages": "^2.3", - "php": ">=5.4.0" + "php": "^7.2|^8.0" }, "require-dev": { - "illuminate/view": "^5.0.x-dev", - "phpunit/phpunit": "^4.8|^5.7|^6.5", - "squizlabs/php_codesniffer": "^3.0", - "symfony/yaml": "~2", - "twig/extensions": "*", - "twig/twig": "^1.31|^2.0" - }, - "suggest": { - "illuminate/view": "Is necessary if you want to use the Blade extractor", - "symfony/yaml": "Is necessary if you want to use the Yaml extractor/generator", - "twig/extensions": "Is necessary if you want to use the Twig extractor", - "twig/twig": "Is necessary if you want to use the Twig extractor" + "brick/varexporter": "^0.3.5", + "friendsofphp/php-cs-fixer": "^3.2", + "oscarotero/php-cs-fixer-config": "^2.0", + "phpunit/phpunit": "^8.0|^9.0", + "squizlabs/php_codesniffer": "^3.0" }, "type": "library", "autoload": { @@ -57,7 +50,7 @@ } ], "description": "PHP gettext manager", - "homepage": "https://github.com/oscarotero/Gettext", + "homepage": "https://github.com/php-gettext/Gettext", "keywords": [ "JS", "gettext", @@ -68,8 +61,8 @@ ], "support": { "email": "oom@oscarotero.com", - "issues": "https://github.com/oscarotero/Gettext/issues", - "source": "https://github.com/php-gettext/Gettext/tree/4.x" + "issues": "https://github.com/php-gettext/Gettext/issues", + "source": "https://github.com/php-gettext/Gettext/tree/v5.6.1" }, "funding": [ { @@ -85,7 +78,7 @@ "type": "patreon" } ], - "time": "2022-02-17T10:14:02+00:00" + "time": "2021-12-04T11:33:21+00:00" }, { "name": "gettext/languages", @@ -161,6 +154,66 @@ ], "time": "2021-11-11T17:30:39+00:00" }, + { + "name": "gettext/translator", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-gettext/Translator.git", + "reference": "0a80844789e6a4ffad417d2053bbb56c83b02803" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-gettext/Translator/zipball/0a80844789e6a4ffad417d2053bbb56c83b02803", + "reference": "0a80844789e6a4ffad417d2053bbb56c83b02803", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.15", + "gettext/gettext": "^5.0.0", + "oscarotero/php-cs-fixer-config": "^1.0", + "phpunit/phpunit": "^8.0", + "squizlabs/php_codesniffer": "^3.0" + }, + "suggest": { + "gettext/gettext": "Is necessary to load and generate array files used by the translator" + }, + "type": "library", + "autoload": { + "psr-4": { + "Gettext\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oscar Otero", + "email": "oom@oscarotero.com", + "homepage": "http://oscarotero.com", + "role": "Developer" + } + ], + "description": "Gettext translator functions", + "homepage": "https://github.com/php-gettext/Translator", + "keywords": [ + "gettext", + "i18n", + "php", + "translator" + ], + "support": { + "email": "oom@oscarotero.com", + "issues": "https://github.com/php-gettext/Translator/issues", + "source": "https://github.com/php-gettext/Translator/tree/v1.0.1" + }, + "time": "2020-12-01T18:51:46+00:00" + }, { "name": "phpmailer/phpmailer", "version": "v6.5.4", @@ -6052,16 +6105,16 @@ }, { "name": "simplesamlphp/simplesamlphp-module-adfs", - "version": "v2.0.0-rc6", + "version": "v2.0.0-rc7", "source": { "type": "git", "url": "https://github.com/simplesamlphp/simplesamlphp-module-adfs.git", - "reference": "3bf9c489ef47b8a3884af4c6341ad0e608b99f85" + "reference": "1896711da0a9a1974ac760afc3ddbb6589498b4d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/simplesamlphp/simplesamlphp-module-adfs/zipball/3bf9c489ef47b8a3884af4c6341ad0e608b99f85", - "reference": "3bf9c489ef47b8a3884af4c6341ad0e608b99f85", + "url": "https://api.github.com/repos/simplesamlphp/simplesamlphp-module-adfs/zipball/1896711da0a9a1974ac760afc3ddbb6589498b4d", + "reference": "1896711da0a9a1974ac760afc3ddbb6589498b4d", "shasum": "" }, "require": { @@ -6099,7 +6152,7 @@ "issues": "https://github.com/simplesamlphp/simplesamlphp-module-adfs/issues", "source": "https://github.com/simplesamlphp/simplesamlphp-module-adfs" }, - "time": "2022-02-13T20:08:00+00:00" + "time": "2022-02-19T15:45:36+00:00" }, { "name": "simplesamlphp/simplesamlphp-test-framework", @@ -6628,7 +6681,6 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { - "gettext/gettext": 20, "simplesamlphp/simplesamlphp-module-adfs": 5 }, "prefer-stable": false, diff --git a/lib/SimpleSAML/Locale/Localization.php b/lib/SimpleSAML/Locale/Localization.php index d88127b04580fdda9fd63fe67d3ccfc052e230ab..9342ee538194e12c69389b703d4ceb064c61bb9b 100644 --- a/lib/SimpleSAML/Locale/Localization.php +++ b/lib/SimpleSAML/Locale/Localization.php @@ -10,8 +10,10 @@ declare(strict_types=1); namespace SimpleSAML\Locale; +use Gettext\Loader\PoLoader; use Gettext\Translations; use Gettext\Translator; +use Gettext\TranslatorFunctions; use SimpleSAML\Configuration; use SimpleSAML\Logger; @@ -84,6 +86,15 @@ class Localization } + /** + * @return \GetText\Translator + */ + public function getTranslator(): Translator + { + return $this->translator; + } + + /** * Dump the default locale directory * @@ -196,7 +207,7 @@ class Localization private function setupTranslator(): void { $this->translator = new Translator(); - $this->translator->register(); + TranslatorFunctions::register($this->translator); } @@ -230,8 +241,9 @@ class Localization $poFile = $domain . '.po'; $poPath = $langPath . $poFile; if (file_exists($poPath) && is_readable($poPath)) { - $translations = Translations::fromPoFile($poPath); - $this->translator->loadTranslations($translations); + $poLoader = new PoLoader(); + $translations = $poLoader->loadFile($poPath); + $this->translator = Translator::createFromTranslations($translations); } else { $error = "Localization file '$poFile' not found in '$langPath', falling back to default"; Logger::debug($_SERVER['PHP_SELF'] . ' - ' . $error); diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php index f8468dd03bc8d3da9163c872391019301226db99..230ce68ff44c083acbc88507e6c9c20e48c1688c 100644 --- a/lib/SimpleSAML/Locale/Translate.php +++ b/lib/SimpleSAML/Locale/Translate.php @@ -10,7 +10,7 @@ declare(strict_types=1); namespace SimpleSAML\Locale; -use Gettext\BaseTranslator; +use Gettext\Translator; use SimpleSAML\Assert\Assert; use SimpleSAML\Configuration; use SimpleSAML\Logger; @@ -81,7 +81,8 @@ class Translate // This may happen if you forget to set a variable and then run undefinedVar through the trans-filter $original = $original ?? 'undefined variable'; - $text = BaseTranslator::$current->gettext($original); + $loc = new Localization(Configuration::getInstance()); + $text = $loc->getTranslator()->gettext($original); if (func_num_args() === 1) { return $text; @@ -98,16 +99,17 @@ class Translate * * @param string|null $original The string before translation. * @param string $plural - * @param string $value + * @param int $value * * @return string The translated string. */ - public static function translatePluralGettext(?string $original, string $plural, string $value): string + public static function translatePluralGettext(?string $original, string $plural, int $value): string { // This may happen if you forget to set a variable and then run undefinedVar through the trans-filter $original = $original ?? 'undefined variable'; - $text = BaseTranslator::$current->ngettext($original, $plural, $value); + $loc = new Localization(Configuration::getInstance()); + $text = $loc->getTranslator()->ngettext($original, $plural, $value); if (func_num_args() === 3) { return $text;