Skip to content

Commit b8e77f8

Browse files
Add a Special Case for Translating Choices in en_US_POSIX
See symfony/symfony#42036 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 (Alpine Linux, for instance).
1 parent 114715a commit b8e77f8

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
@@ -80,6 +80,17 @@ public function testTransChoiceWithDefaultLocale($expected, $id, $number)
8080
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
8181
}
8282

83+
/**
84+
* @dataProvider getTransChoiceTests
85+
*/
86+
public function testTransChoiceWithEnUsPosix($expected, $id, $number)
87+
{
88+
$translator = $this->getTranslator();
89+
$translator->setLocale('en_US_POSIX');
90+
91+
$this->assertEquals($expected, $translator->trans($id, ['%count%' => $number]));
92+
}
93+
8394
public function testGetSetLocale()
8495
{
8596
$translator = $this->getTranslator();
@@ -296,7 +307,7 @@ public function successLangcodes()
296307
{
297308
return [
298309
['1', ['ay', 'bo', 'cgg', 'dz', 'id', 'ja', 'jbo', 'ka', 'kk', 'km', 'ko', 'ky']],
299-
['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM']],
310+
['2', ['nl', 'fr', 'en', 'de', 'de_GE', 'hy', 'hy_AM', 'en_US_POSIX']],
300311
['3', ['be', 'bs', 'cs', 'hr']],
301312
['4', ['cy', 'mt', 'sl']],
302313
['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)