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 5e80445

Browse filesBrowse 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 #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 ------- f0bb7a3 Add a Special Case for Translating Choices in en_US_POSIX
2 parents 19fdcba + f0bb7a3 commit 5e80445
Copy full SHA for 5e80445

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
@@ -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']],

‎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.