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

Add a Special Case for Translating Choices in en_US_POSIX #42068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion 3 src/Symfony/Component/Translation/PluralizationRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, '_')));
}

Expand Down Expand Up @@ -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':
Expand Down
13 changes: 12 additions & 1 deletion 13 src/Symfony/Contracts/Translation/Test/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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']],
Expand Down
3 changes: 2 additions & 1 deletion 3 src/Symfony/Contracts/Translation/TranslatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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':
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.