From 1f1021bf9e1c82a60d7f6726bce5d71b5d6c18d3 Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Sat, 11 Aug 2018 22:25:00 +0300 Subject: [PATCH 01/20] Add helper trait to provide type-hinting for zend-view --- src/View/HelperTrait.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/View/HelperTrait.php diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php new file mode 100644 index 00000000..85644438 --- /dev/null +++ b/src/View/HelperTrait.php @@ -0,0 +1,30 @@ + Date: Wed, 5 Sep 2018 12:02:17 +0300 Subject: [PATCH 02/20] Add ending doc block annotation for ignoring coding standards --- src/View/HelperTrait.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php index 85644438..b23b8465 100644 --- a/src/View/HelperTrait.php +++ b/src/View/HelperTrait.php @@ -5,6 +5,7 @@ use IntlDateFormatter; // @codingStandardsIgnoreStart + /** * Trait HelperTrait * @@ -28,3 +29,4 @@ trait HelperTrait { } +// @codingStandardsIgnoreEnd From 7f3a1fc0134b8a92c8b72147f981885f7697c904 Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Wed, 5 Sep 2018 12:04:57 +0300 Subject: [PATCH 03/20] Add doc block with copyright and license information --- src/View/HelperTrait.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php index b23b8465..0624ff0a 100644 --- a/src/View/HelperTrait.php +++ b/src/View/HelperTrait.php @@ -1,4 +1,9 @@ Date: Wed, 5 Sep 2018 12:08:40 +0300 Subject: [PATCH 04/20] Change comment in doc-block's description to properly address Zend Framework components --- src/View/HelperTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php index 0624ff0a..92421516 100644 --- a/src/View/HelperTrait.php +++ b/src/View/HelperTrait.php @@ -20,7 +20,7 @@ * * The base class is PhpRenderer, followed by the helper trait from * the zend-i18n component. However, multiple helper traits from different - * Zend components can be chained afterwards. + * Zend Framework components can be chained afterwards. * * @example @var \Zend\View\Renderer\PhpRenderer|\Zend\I18n\View\HelperTrait $this * From 9c9c8f75de2ca8126e0319579081ac8da5b3b826 Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Wed, 5 Sep 2018 12:35:42 +0300 Subject: [PATCH 05/20] Add data types for all @method parameters in the helper trait --- src/View/HelperTrait.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php index 92421516..59d6461f 100644 --- a/src/View/HelperTrait.php +++ b/src/View/HelperTrait.php @@ -24,12 +24,12 @@ * * @example @var \Zend\View\Renderer\PhpRenderer|\Zend\I18n\View\HelperTrait $this * - * @method string currencyFormat($number, $currencyCode = null, $showDecimals = null, $locale = null, $pattern = null) - * @method string dateFormat($date, $dateType = IntlDateFormatter::NONE, $timeType = IntlDateFormatter::NONE, $locale = null, $pattern = null) - * @method string numberFormat($number, $formatStyle = null, $formatType = null, $locale = null, $decimals = null, array $textAttributes = null) - * @method string plural($strings, $number) - * @method string translate($message, $textDomain = null, $locale = null) - * @method string translatePlural($singular, $plural, $number, $textDomain = null, $locale = null) + * @method string currencyFormat(float $number, string|null $currencyCode = null, bool|null $showDecimals = null, string|null $locale = null, string|null $pattern = null) + * @method string dateFormat(\DateTime|int|array $date, int $dateType = IntlDateFormatter::NONE, int $timeType = IntlDateFormatter::NONE, string|null $locale = null, string|null $pattern = null) + * @method string numberFormat(int|float $number, int|null $formatStyle = null, int|null $formatType = null, string|null $locale = null, int|null $decimals = null, array|null $textAttributes = null) + * @method string plural(array|string $strings, int $number) + * @method string translate(string $message, string|null $textDomain = null, string|null $locale = null) + * @method string translatePlural(string $singular, string $plural, int $number, string|null $textDomain = null, string|null $locale = null) */ trait HelperTrait { From 013008b9d854933971d663bac6256e65390f37b7 Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Wed, 5 Sep 2018 12:36:57 +0300 Subject: [PATCH 06/20] Add a more descriptive title of the helper trait --- src/View/HelperTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php index 59d6461f..b0b5179a 100644 --- a/src/View/HelperTrait.php +++ b/src/View/HelperTrait.php @@ -12,7 +12,7 @@ // @codingStandardsIgnoreStart /** - * Trait HelperTrait + * Helper trait for auto-completion of code in modern IDEs. * * The trait provides convenience methods for view helpers, * defined by the zend-i18n component. It is designed to be used From f9b5d9cd8cde91c30541b0adea6bd2bb428e2422 Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Thu, 6 Sep 2018 01:47:22 +0300 Subject: [PATCH 07/20] Replace the year range with the current year in the copyright doc-block --- src/View/HelperTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/HelperTrait.php b/src/View/HelperTrait.php index b0b5179a..424512fc 100644 --- a/src/View/HelperTrait.php +++ b/src/View/HelperTrait.php @@ -1,7 +1,7 @@ Date: Wed, 12 Sep 2018 16:59:11 +0300 Subject: [PATCH 08/20] Add documentation for HelperTrait for IDE auto-completion --- docs/book/view-helpers.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/book/view-helpers.md b/docs/book/view-helpers.md index 48d93612..bf405790 100644 --- a/docs/book/view-helpers.md +++ b/docs/book/view-helpers.md @@ -7,6 +7,29 @@ displaying translated content. See the [zend-view helpers documentation](http://framework.zend.com/manual/current/en/modules/zend.view.helpers.html#zend-view-helpers) for more information. +## IDE auto-completion in templates + +The `Zend\I18n\View\Helper\HelperTrait` trait can be used to provide +auto-completion for modern IDEs. It defines the aliases of the view helpers in a +DocBlock as `@method` tags. + +### Usage + +In order to allow auto-completion in templates, `$this` variable should be +type-hinted via a DocBlock at the top of your template. It is recommended that +you always add the `Zend\View\Renderer\PhpRenderer` as the first type, so that +the IDE can auto-suggest the default view helpers from `zend-view`. Next, chain +the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical bar) `|`: +```php +/** + * @var Zend\I18n\View\Helper\HelperTrait|Zend\I18n\View\Helper\HelperTrait $this + */ +``` + +You may chain as many `HelperTrait` traits as you like, depending on view +helpers from which Zend Framework component you are using and would like to +provide auto-completion for. + ## CurrencyFormat Helper The `CurrencyFormat` view helper can be used to simplify rendering of localized From 3e04da1c154b44efe05525041de7905b717c49e1 Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Wed, 12 Sep 2018 17:03:25 +0300 Subject: [PATCH 09/20] Fix wrong type-hint --- docs/book/view-helpers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/book/view-helpers.md b/docs/book/view-helpers.md index bf405790..3c476f42 100644 --- a/docs/book/view-helpers.md +++ b/docs/book/view-helpers.md @@ -22,7 +22,7 @@ the IDE can auto-suggest the default view helpers from `zend-view`. Next, chain the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical bar) `|`: ```php /** - * @var Zend\I18n\View\Helper\HelperTrait|Zend\I18n\View\Helper\HelperTrait $this + * @var Zend\View\Renderer\PhpRenderer|Zend\I18n\View\Helper\HelperTrait $this */ ``` From 794901446d9bcd919dde0933fa47dff526fb4adc Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Wed, 12 Sep 2018 18:14:49 +0300 Subject: [PATCH 10/20] Move the docs section for IDE auto-completion inside a block quote and nest the headings one level further --- docs/book/view-helpers.md | 45 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/docs/book/view-helpers.md b/docs/book/view-helpers.md index 3c476f42..68bc994a 100644 --- a/docs/book/view-helpers.md +++ b/docs/book/view-helpers.md @@ -7,28 +7,29 @@ displaying translated content. See the [zend-view helpers documentation](http://framework.zend.com/manual/current/en/modules/zend.view.helpers.html#zend-view-helpers) for more information. -## IDE auto-completion in templates - -The `Zend\I18n\View\Helper\HelperTrait` trait can be used to provide -auto-completion for modern IDEs. It defines the aliases of the view helpers in a -DocBlock as `@method` tags. - -### Usage - -In order to allow auto-completion in templates, `$this` variable should be -type-hinted via a DocBlock at the top of your template. It is recommended that -you always add the `Zend\View\Renderer\PhpRenderer` as the first type, so that -the IDE can auto-suggest the default view helpers from `zend-view`. Next, chain -the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical bar) `|`: -```php -/** - * @var Zend\View\Renderer\PhpRenderer|Zend\I18n\View\Helper\HelperTrait $this - */ -``` - -You may chain as many `HelperTrait` traits as you like, depending on view -helpers from which Zend Framework component you are using and would like to -provide auto-completion for. +> ### IDE auto-completion in templates +> +> The `Zend\I18n\View\Helper\HelperTrait` trait can be used to provide +> auto-completion for modern IDEs. It defines the aliases of the view helpers in +> a DocBlock as `@method` tags. +> +> #### Usage +> +> In order to allow auto-completion in templates, `$this` variable should be +> type-hinted via a DocBlock at the top of your template. It is recommended that +> you always add the `Zend\View\Renderer\PhpRenderer` as the first type, so that +> the IDE can auto-suggest the default view helpers from `zend-view`. Next, +> chain the `HelperTrait` from `zend-i18n` with a pipe symbol (a.k.a. vertical +> bar) `|`: +> ```php +> /** +> * @var Zend\View\Renderer\PhpRenderer|Zend\I18n\View\Helper\HelperTrait $this +> */ +> ``` +> +> You may chain as many `HelperTrait` traits as you like, depending on view +> helpers from which Zend Framework component you are using and would like to +> provide auto-completion for. ## CurrencyFormat Helper From fa2136b3473161ee5d1fc654a9183eee9000971b Mon Sep 17 00:00:00 2001 From: Cvetomir Lazarov Date: Wed, 12 Sep 2018 21:30:05 +0300 Subject: [PATCH 11/20] Fix wrong namespace in docs for HelperTrait and re-align code example --- docs/book/view-helpers.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/book/view-helpers.md b/docs/book/view-helpers.md index 68bc994a..0d92a597 100644 --- a/docs/book/view-helpers.md +++ b/docs/book/view-helpers.md @@ -9,9 +9,9 @@ for more information. > ### IDE auto-completion in templates > -> The `Zend\I18n\View\Helper\HelperTrait` trait can be used to provide -> auto-completion for modern IDEs. It defines the aliases of the view helpers in -> a DocBlock as `@method` tags. +> The `Zend\I18n\View\HelperTrait` trait can be used to provide auto-completion +> for modern IDEs. It defines the aliases of the view helpers in a DocBlock as +> `@method` tags. > > #### Usage > @@ -23,8 +23,8 @@ for more information. > bar) `|`: > ```php > /** -> * @var Zend\View\Renderer\PhpRenderer|Zend\I18n\View\Helper\HelperTrait $this -> */ +> * @var Zend\View\Renderer\PhpRenderer|Zend\I18n\View\HelperTrait $this +> */ > ``` > > You may chain as many `HelperTrait` traits as you like, depending on view From d936e0057b23c3d77d86442c15d3016d2654d5e3 Mon Sep 17 00:00:00 2001 From: Adam Culp Date: Mon, 18 Nov 2019 10:37:04 -0500 Subject: [PATCH 12/20] Moved ext-intl to required instead of suggested. Because the extension is not included in all default builds of PHP, and is required for translate usage. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3597ff09..3e8a1955 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ }, "require": { "php": "^5.6 || ^7.0", + "ext-intl": "Required for most features of Zend\\I18n; not included in all default builds of PHP", "zendframework/zend-stdlib": "^2.7 || ^3.0" }, "require-dev": { @@ -31,7 +32,6 @@ "zendframework/zend-view": "^2.6.3" }, "suggest": { - "ext-intl": "Required for most features of Zend\\I18n; included in default builds of PHP", "zendframework/zend-cache": "Zend\\Cache component", "zendframework/zend-config": "Zend\\Config component", "zendframework/zend-eventmanager": "You should install this package to use the events in the translator", From f3902c95cabfff6a87f3b1b05d1dba6bd9dea6f7 Mon Sep 17 00:00:00 2001 From: Adam Culp Date: Mon, 18 Nov 2019 10:56:20 -0500 Subject: [PATCH 13/20] Changed comment to an asterisk, per Composer standard. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3e8a1955..64bea035 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require": { "php": "^5.6 || ^7.0", - "ext-intl": "Required for most features of Zend\\I18n; not included in all default builds of PHP", + "ext-intl": "*", "zendframework/zend-stdlib": "^2.7 || ^3.0" }, "require-dev": { From 1e988c8cf256d809cf0e282144b05227f7aec509 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 18 Nov 2019 14:14:19 -0600 Subject: [PATCH 14/20] docs: Added CHANGELOG entry for #102 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02567707..3b0e445b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ All notable changes to this project will be documented in this file, in reverse ### Added -- Nothing. +- [#102](https://github.com/zendframework/zend-i18n/pull/102) adds `Zend\I18n\View\HelperTrait`, which provides annotations describing the various helpers zend-i18n provides to a zend-view renderer. The trait can be used in combination with `Zend\View\Renderer\PhpRenderer` in annotations on the `$this` variable within view scripts to provide IDE autocompletion for helper-provided methods. ### Changed From e845e139530b0bdd0e6e4df36cab69d330591fae Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 18 Nov 2019 14:16:55 -0600 Subject: [PATCH 15/20] docs: adds CHANGELOG entry for #126 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b0e445b..57fd15f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse ### Changed -- Nothing. +- [#126](https://github.com/zendframework/zend-i18n/pull/126) modifies the package definition to put an explicit requirement on ext-intl, as it is required for the majority of functionality. Users have indicated multiple times confusion about why the component does not work after installation, when attempting to use intl functionality; requiring the extension resolves that issue. ### Deprecated From 307b43097973e4c5f7481be72ac0bf813f83bcc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Fri, 22 Mar 2019 14:48:39 +0100 Subject: [PATCH 16/20] fallback to sourcecode if pluralform exists but is not translated --- src/Translator/Translator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index b7230ba2..3c64a526 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -417,7 +417,11 @@ public function translatePlural( ); } - return $translation[$index]; + if ($translation[$index] !== '') { + return $translation[$index]; + } + + return $index === 0 ? $singular : $plural; } /** From 66808725dd898a52aebfe03ded38a6bc950a439d Mon Sep 17 00:00:00 2001 From: David Lutzweiler Date: Thu, 28 Mar 2019 15:21:12 +0100 Subject: [PATCH 17/20] write some unittests for plural-fallback and allow fallback-locales --- src/Translator/Translator.php | 44 +++++++-------- test/Translator/TranslatorTest.php | 53 +++++++++++++++++++ .../_files/testarray/translation-de_DE.php | 5 ++ 3 files changed, 77 insertions(+), 25 deletions(-) diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index 3c64a526..6b2208ba 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -387,40 +387,34 @@ public function translatePlural( $locale = $locale ?: $this->getLocale(); $translation = $this->getTranslatedMessage($singular, $locale, $textDomain); - if ($translation === null || $translation === '') { - if (null !== ($fallbackLocale = $this->getFallbackLocale()) - && $locale !== $fallbackLocale - ) { - return $this->translatePlural( - $singular, - $plural, - $number, - $textDomain, - $fallbackLocale - ); - } - - return ($number == 1 ? $singular : $plural); - } - if (is_string($translation)) { $translation = [$translation]; } - $index = $this->messages[$textDomain][$locale] - ->getPluralRule() - ->evaluate($number); - - if (! isset($translation[$index])) { - throw new Exception\OutOfBoundsException( - sprintf('Provided index %d does not exist in plural array', $index) - ); + $index = ($number === 1) ? 0 : 1; // en_EN Plural rule + if ($this->messages[$textDomain][$locale] instanceof TextDomain) { + $index = $this->messages[$textDomain][$locale] + ->getPluralRule() + ->evaluate($number); } - if ($translation[$index] !== '') { + if (isset($translation[$index]) && $translation[$index] !== '' && $translation[$index] !== null) { return $translation[$index]; } + if ( + null !== ($fallbackLocale = $this->getFallbackLocale()) + && $locale !== $fallbackLocale + ) { + return $this->translatePlural( + $singular, + $plural, + $number, + $textDomain, + $fallbackLocale + ); + } + return $index === 0 ? $singular : $plural; } diff --git a/test/Translator/TranslatorTest.php b/test/Translator/TranslatorTest.php index 86169dc7..b6bb66cb 100644 --- a/test/Translator/TranslatorTest.php +++ b/test/Translator/TranslatorTest.php @@ -255,6 +255,44 @@ public function testTranslatePlurals() $this->assertEquals('Message 5 (en) Plural 2', $pl2); } + public function testTranslatePluralsNonExistantLocale() + { + $this->translator->addTranslationFilePattern( + 'phparray', + $this->testFilesDir . '/testarray', + 'translation-%s.php' + ); + + $this->translator->setLocale('es_ES'); + + $pl0 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 1); + $pl1 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 2); + $pl2 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 10); + + $this->assertEquals('Message 5', $pl0); + $this->assertEquals('Message 5 Plural', $pl1); + $this->assertEquals('Message 5 Plural', $pl2); + } + + public function testTranslatePluralsNonExistantTranslation() + { + $this->translator->addTranslationFilePattern( + 'phparray', + $this->testFilesDir . '/testarray', + 'translation-%s.php' + ); + + $this->translator->setLocale('de_DE'); + + $pl0 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 1); + $pl1 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 2); + $pl2 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 10); + + $this->assertEquals('Message 12', $pl0); + $this->assertEquals('Message 12 Plural', $pl1); + $this->assertEquals('Message 12 Plural', $pl2); + } + public function testTranslateNoPlurals() { // Some languages such as Japanese and Chinese does not have plural forms @@ -296,6 +334,21 @@ public function testTranslateNonExistantLocale() $this->assertEquals('Message 9', $this->translator->translate('Message 9')); } + public function testTranslateNonExistantTranslation() + { + $this->translator->addTranslationFilePattern( + 'phparray', + $this->testFilesDir . '/testarray', + 'translation-%s.php' + ); + + // Test that a locale without translations does not cause warnings + + $this->translator->setLocale('de_DE'); + + $this->assertEquals('Message 13', $this->translator->translate('Message 13')); + } + public function testEnableDisableEventManger() { $this->assertFalse($this->translator->isEventManagerEnabled(), 'Default value'); diff --git a/test/Translator/_files/testarray/translation-de_DE.php b/test/Translator/_files/testarray/translation-de_DE.php index c1ab7b72..883cb8bd 100644 --- a/test/Translator/_files/testarray/translation-de_DE.php +++ b/test/Translator/_files/testarray/translation-de_DE.php @@ -15,4 +15,9 @@ 'Nachricht 10 - 0', 'Nachricht 10 - 1', ], + 'Message 12' => [ + '', + '', + ], + 'Message 13' => '', ]; From 525a5b4a72593cd1de4e13ee7ea500c009e16939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Bl=C3=BCmel?= Date: Fri, 29 Mar 2019 01:27:34 +0100 Subject: [PATCH 18/20] fix whitespace --- src/Translator/Translator.php | 19 +++--- test/Translator/TranslatorTest.php | 96 +++++++++++++++--------------- 2 files changed, 57 insertions(+), 58 deletions(-) diff --git a/src/Translator/Translator.php b/src/Translator/Translator.php index 6b2208ba..b88ce501 100644 --- a/src/Translator/Translator.php +++ b/src/Translator/Translator.php @@ -402,18 +402,17 @@ public function translatePlural( return $translation[$index]; } - if ( - null !== ($fallbackLocale = $this->getFallbackLocale()) + if (null !== ($fallbackLocale = $this->getFallbackLocale()) && $locale !== $fallbackLocale ) { - return $this->translatePlural( - $singular, - $plural, - $number, - $textDomain, - $fallbackLocale - ); - } + return $this->translatePlural( + $singular, + $plural, + $number, + $textDomain, + $fallbackLocale + ); + } return $index === 0 ? $singular : $plural; } diff --git a/test/Translator/TranslatorTest.php b/test/Translator/TranslatorTest.php index b6bb66cb..bbed4557 100644 --- a/test/Translator/TranslatorTest.php +++ b/test/Translator/TranslatorTest.php @@ -255,43 +255,43 @@ public function testTranslatePlurals() $this->assertEquals('Message 5 (en) Plural 2', $pl2); } - public function testTranslatePluralsNonExistantLocale() - { - $this->translator->addTranslationFilePattern( - 'phparray', - $this->testFilesDir . '/testarray', - 'translation-%s.php' - ); - - $this->translator->setLocale('es_ES'); - - $pl0 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 1); - $pl1 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 2); - $pl2 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 10); - - $this->assertEquals('Message 5', $pl0); - $this->assertEquals('Message 5 Plural', $pl1); - $this->assertEquals('Message 5 Plural', $pl2); - } - - public function testTranslatePluralsNonExistantTranslation() - { - $this->translator->addTranslationFilePattern( - 'phparray', - $this->testFilesDir . '/testarray', - 'translation-%s.php' - ); - - $this->translator->setLocale('de_DE'); - - $pl0 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 1); - $pl1 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 2); - $pl2 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 10); - - $this->assertEquals('Message 12', $pl0); - $this->assertEquals('Message 12 Plural', $pl1); - $this->assertEquals('Message 12 Plural', $pl2); - } + public function testTranslatePluralsNonExistantLocale() + { + $this->translator->addTranslationFilePattern( + 'phparray', + $this->testFilesDir . '/testarray', + 'translation-%s.php' + ); + + $this->translator->setLocale('es_ES'); + + $pl0 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 1); + $pl1 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 2); + $pl2 = $this->translator->translatePlural('Message 5', 'Message 5 Plural', 10); + + $this->assertEquals('Message 5', $pl0); + $this->assertEquals('Message 5 Plural', $pl1); + $this->assertEquals('Message 5 Plural', $pl2); + } + + public function testTranslatePluralsNonExistantTranslation() + { + $this->translator->addTranslationFilePattern( + 'phparray', + $this->testFilesDir . '/testarray', + 'translation-%s.php' + ); + + $this->translator->setLocale('de_DE'); + + $pl0 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 1); + $pl1 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 2); + $pl2 = $this->translator->translatePlural('Message 12', 'Message 12 Plural', 10); + + $this->assertEquals('Message 12', $pl0); + $this->assertEquals('Message 12 Plural', $pl1); + $this->assertEquals('Message 12 Plural', $pl2); + } public function testTranslateNoPlurals() { @@ -334,20 +334,20 @@ public function testTranslateNonExistantLocale() $this->assertEquals('Message 9', $this->translator->translate('Message 9')); } - public function testTranslateNonExistantTranslation() - { - $this->translator->addTranslationFilePattern( - 'phparray', - $this->testFilesDir . '/testarray', - 'translation-%s.php' - ); + public function testTranslateNonExistantTranslation() + { + $this->translator->addTranslationFilePattern( + 'phparray', + $this->testFilesDir . '/testarray', + 'translation-%s.php' + ); - // Test that a locale without translations does not cause warnings + // Test that a locale without translations does not cause warnings - $this->translator->setLocale('de_DE'); + $this->translator->setLocale('de_DE'); - $this->assertEquals('Message 13', $this->translator->translate('Message 13')); - } + $this->assertEquals('Message 13', $this->translator->translate('Message 13')); + } public function testEnableDisableEventManger() { From e938dc54f01b00b08954f3560bfc4deb5cfc5879 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 18 Nov 2019 14:25:31 -0600 Subject: [PATCH 19/20] docs: adds CHANGELOG entry for #110 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57fd15f7..3d6b680b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file, in reverse ### Changed +- [#110](https://github.com/zendframework/zend-i18n/pull/110) modifies how `translatePlural()` works when a msgid is present, but no translations are present. It now properly returns the source-code if unable to translate the message, instead of returning an empty string (which is the behavior under `translate()` as well). + - [#126](https://github.com/zendframework/zend-i18n/pull/126) modifies the package definition to put an explicit requirement on ext-intl, as it is required for the majority of functionality. Users have indicated multiple times confusion about why the component does not work after installation, when attempting to use intl functionality; requiring the extension resolves that issue. ### Deprecated From dc9f122cc225fd2e2d0a58ecf20551b7b18f4857 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Mon, 18 Nov 2019 14:29:37 -0600 Subject: [PATCH 20/20] release: 2.10.0 readiness - Updates CHANGELOG: - Removes empty 2.9.3 changelog - Adds release date for 2.10.0 changelog - Bumps branch aliases: - dev-master => 2.10.x-dev - dev-develop => 2.11.x-dev --- CHANGELOG.md | 24 +----------------------- composer.json | 4 ++-- composer.lock | 5 +++-- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6b680b..3c063ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 2.10.0 - TBD +## 2.10.0 - 2019-11-18 ### Added @@ -26,28 +26,6 @@ All notable changes to this project will be documented in this file, in reverse - Nothing. -## 2.9.3 - TBD - -### Added - -- Nothing. - -### Changed - -- Nothing. - -### Deprecated - -- Nothing. - -### Removed - -- Nothing. - -### Fixed - -- Nothing. - ## 2.9.2 - 2019-09-30 ### Added diff --git a/composer.json b/composer.json index 64bea035..f4128705 100644 --- a/composer.json +++ b/composer.json @@ -56,8 +56,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.9.x-dev", - "dev-develop": "2.10.x-dev" + "dev-master": "2.10.x-dev", + "dev-develop": "2.11.x-dev" }, "zf": { "component": "Zend\\I18n", diff --git a/composer.lock b/composer.lock index 060040c9..e0e253ab 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7ef021512fc5c8b2657b4651b2d9c668", + "content-hash": "d8372864bd80035f9a90e9318be38672", "packages": [ { "name": "zendframework/zend-stdlib", @@ -2228,7 +2228,8 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^5.6 || ^7.0" + "php": "^5.6 || ^7.0", + "ext-intl": "*" }, "platform-dev": [] }