diff --git a/src/Symfony/Component/Translation/PluralizationRules.php b/src/Symfony/Component/Translation/PluralizationRules.php index 2a46ce094f434..e69ceabc17abc 100644 --- a/src/Symfony/Component/Translation/PluralizationRules.php +++ b/src/Symfony/Component/Translation/PluralizationRules.php @@ -43,7 +43,7 @@ public static function get($number, $locale/*, bool $triggerDeprecation = true*/ $locale = 'xbr'; } - if (\strlen($locale) > 3) { + if ('en_US_POSIX' !== $locale && \strlen($locale) > 3) { $locale = substr($locale, 0, -\strlen(strrchr($locale, '_'))); } @@ -88,6 +88,7 @@ public static function get($number, $locale/*, bool $triggerDeprecation = true*/ case 'de': case 'el': case 'en': + case 'en_US_POSIX': case 'eo': case 'es': case 'et': diff --git a/src/Symfony/Contracts/Translation/Test/TranslatorTest.php b/src/Symfony/Contracts/Translation/Test/TranslatorTest.php index 196ec1859f812..35519f34b9882 100644 --- a/src/Symfony/Contracts/Translation/Test/TranslatorTest.php +++ b/src/Symfony/Contracts/Translation/Test/TranslatorTest.php @@ -80,6 +80,17 @@ public function testTransChoiceWithDefaultLocale($expected, $id, $number) $this->assertEquals($expected, $translator->trans($id, ['%count%' => $number])); } + /** + * @dataProvider getTransChoiceTests + */ + public function testTransChoiceWithEnUsPosix($expected, $id, $number) + { + $translator = $this->getTranslator(); + $translator->setLocale('en_US_POSIX'); + + $this->assertEquals($expected, $translator->trans($id, ['%count%' => $number])); + } + public function testGetSetLocale() { $translator = $this->getTranslator(); @@ -296,7 +307,7 @@ public function successLangcodes() { return [ ['1', ['ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky']], - ['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM']], + ['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM', 'en_US_POSIX']], ['3', ['be', 'bs', 'cs', 'hr']], ['4', ['cy', 'mt', 'sl']], ['6', ['ar']], diff --git a/src/Symfony/Contracts/Translation/TranslatorTrait.php b/src/Symfony/Contracts/Translation/TranslatorTrait.php index 2c09c5f14d5e5..92a6a002144ea 100644 --- a/src/Symfony/Contracts/Translation/TranslatorTrait.php +++ b/src/Symfony/Contracts/Translation/TranslatorTrait.php @@ -140,7 +140,7 @@ private function getPluralizationRule(float $number, string $locale): int { $number = abs($number); - switch ('pt_BR' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) { + switch ('pt_BR' !== $locale && 'en_US_POSIX' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) { case 'af': case 'bn': case 'bg': @@ -149,6 +149,7 @@ private function getPluralizationRule(float $number, string $locale): int case 'de': case 'el': case 'en': + case 'en_US_POSIX': case 'eo': case 'es': case 'et':