Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f0bb7a3

Browse filesBrowse files
Add a Special Case for Translating Choices in en_US_POSIX
See #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 7253299 commit f0bb7a3
Copy full SHA for f0bb7a3

File tree

3 files changed

+16
-3
lines changed
Filter options

3 files changed

+16
-3
lines changed

‎src/Symfony/Component/Translation/PluralizationRules.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Translation/PluralizationRules.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function get($number, $locale/*, bool $triggerDeprecation = true*/
4343
$locale = 'xbr';
4444
}
4545

46-
if (\strlen($locale) > 3) {
46+
if ('en_US_POSIX' !== $locale && \strlen($locale) > 3) {
4747
$locale = substr($locale, 0, -\strlen(strrchr($locale, '_')));
4848
}
4949

@@ -88,6 +88,7 @@ public static function get($number, $locale/*, bool $triggerDeprecation = true*/
8888
case 'de':
8989
case 'el':
9090
case 'en':
91+
case 'en_US_POSIX':
9192
case 'eo':
9293
case 'es':
9394
case 'et':

‎src/Symfony/Contracts/Translation/Test/TranslatorTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Translation/Test/TranslatorTest.php
+12-1Lines 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']],

‎src/Symfony/Contracts/Translation/TranslatorTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Translation/TranslatorTrait.php
+2-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.