Skip to content

Commit 0d62799

Browse files
bug #42068 Add a Special Case for Translating Choices in en_US_POSIX (chrisguitarguy)
This PR was merged into the 4.4 branch. Discussion ---------- Add a Special Case for Translating Choices in en_US_POSIX | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix symfony/symfony#42036 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a <!-- required for new features --> This adds a special case similar to `pt_BR` for handling `en_US_POSIX` which is set as the default locale on some operating systems. ~Two tests here might be over the top, not sure.~ Not over the top! One of them caught the same issue in the translation component itself 🎉 Commits ------- f0bb7a36c5 Add a Special Case for Translating Choices in en_US_POSIX
2 parents 9f2d3d6 + b8e77f8 commit 0d62799

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Translation/Test/TranslatorTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ public function testTransChoiceWithDefaultLocale($expected, $id, $number)
8383
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
8484
}
8585

86+
/**
87+
* @dataProvider getTransChoiceTests
88+
*/
89+
public function testTransChoiceWithEnUsPosix($expected, $id, $number)
90+
{
91+
$translator = $this->getTranslator();
92+
$translator->setLocale('en_US_POSIX');
93+
94+
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
95+
}
96+
8697
public function testGetSetLocale()
8798
{
8899
$translator = $this->getTranslator();
@@ -299,7 +310,7 @@ public function successLangcodes()
299310
{
300311
return [
301312
['1', ['ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky']],
302-
['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM']],
313+
['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM', 'en_US_POSIX']],
303314
['3', ['be', 'bs', 'cs', 'hr']],
304315
['4', ['cy', 'mt', 'sl']],
305316
['6', ['ar']],

Translation/TranslatorTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ private function getPluralizationRule(float $number, string $locale): int
140140
{
141141
$number = abs($number);
142142

143-
switch ('pt_BR' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) {
143+
switch ('pt_BR' !== $locale && 'en_US_POSIX' !== $locale && \strlen($locale) > 3 ? substr($locale, 0, strrpos($locale, '_')) : $locale) {
144144
case 'af':
145145
case 'bn':
146146
case 'bg':
@@ -149,6 +149,7 @@ private function getPluralizationRule(float $number, string $locale): int
149149
case 'de':
150150
case 'el':
151151
case 'en':
152+
case 'en_US_POSIX':
152153
case 'eo':
153154
case 'es':
154155
case 'et':

0 commit comments

Comments
 (0)