8000 Merge branch '5.x' into 5.next · cakephp/cakephp@9ad91d6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ad91d6

Browse files
committed
Merge branch '5.x' into 5.next
2 parents 022475e + 2d42240 commit 9ad91d6

File tree

4 files changed

+57
-14
lines changed

4 files changed

+57
-14
lines changed

src/I18n/PluralRules.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ class PluralRules
5454
'el' => 1,
5555
'en' => 1,
5656
'eo' => 1,
57-
'es' => 1,
57+
'es' => 17,
5858
'et' => 1,
5959
'eu' => 1,
6060
'fa' => 1,
6161
'fi' => 1,
6262
'fil' => 2,
6363
'fo' => 1,
64-
'fr' => 2,
64+
'fr' => 16,
6565
'fur' => 1,
6666
'fy' => 1,
6767
'ga' => 5,
@@ -75,7 +75,7 @@ class PluralRules
7575
'hu' => 1,
7676
'id' => 0,
7777
'is' => 15,
78-
'it' => 1,
78+
'it' => 17,
7979
'ja' => 0,
8080
'jv' => 0,
8181
'ka' => 0,
@@ -107,8 +107,8 @@ class PluralRules
107107
'pap' => 1,
108108
'pl' => 11,
109109
'ps' => 1,
110-
'pt_BR' => 2,
111-
'pt' => 1,
110+
'pt_PT' => 17,
111+
'pt' => 16,
112112
'ro' => 12,
113113
'ru' => 3,
114114
'sk' => 4,
@@ -139,8 +139,7 @@ class PluralRules
139139
* @param string $locale The locale to get the rule calculated for.
140140
* @param int $n The number to apply the rules to.
141141
* @return int The plural rule number that should be used.
142-
* @link http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
143-
* @link https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
142+
* @link https://php-gettext.github.io/Languages/#47
144143
*/
145144
public static function calculate(string $locale, int $n): int
146145
{
@@ -190,6 +189,8 @@ public static function calculate(string $locale, int $n): int
190189
($n === 2 ? 1 :
191190
($n !== 8 && $n !== 11 ? 2 : 3)),
192191
15 => $n % 10 !== 1 || $n % 100 === 11 ? 1 : 0,
192+
16 => $n === 0 || $n === 1 ? 0 : ($n % 1000000 === 0 ? 1 : 2),
193+
17 => $n === 1 ? 0 : ($n !== 0 && $n % 1000000 === 0 ? 1 : 2),
193194
default => throw new CakeException('Unable to find plural rule number.'),
194195
};
195196
}

tests/TestCase/I18n/I18nTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,35 @@ public function testPluralSelectionRussian(): void
135135
$this->assertSame('7 months everything else', $result);
136136
}
137137

138+
public function testPluralSelectionFrench(): void
139+
{
140+
$translator = I18n::getTranslator('default', 'fr');
141+
142+
$result = $translator->translate('{0} apples', ['_count' => 1, 1]);
143+
$this->assertSame('1 pomme', $result);
144+
145+
$result = $translator->translate('{0} apples', ['_count' => 2, 2]);
146+
$this->assertSame('2 pommes', $result);
147+
148+
$result = $translator->translate('{0} apples', ['_count' => 1000000, 1000000]);
149+
$this->assertSame('1000000 de pommes', $result);
150+
151+
$result = $translator->translate('{0} apples', ['_count' => 1000001, 1000001]);
152+
$this->assertSame('1000001 pommes', $result);
153+
154+
$result = $translator->translate('{0} bananas', ['_count' => 1, 1]);
155+
$this->assertSame('1 banana fr', $result);
156+
157+
$result = $translator->translate('{0} bananas', ['_count' => 2, 2]);
158+
$this->assertSame('2 bananas fr', $result);
159+
160+
$result = $translator->translate('{0} bananas', ['_count' => 1000000, 1000000]);
161+
$this->assertSame('1000000 bananas fr', $result);
162+
163+
$result = $translator->translate('{0} bananas', ['_count' => 1000001, 1000001]);
164+
$this->assertSame('1000001 bananas fr', $result);
165+
}
166+
138167
/**
139168
* Tests that custom translation packages can be created on the fly and used later on
140169
*/

tests/TestCase/I18n/PluralRulesTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ public static function localesProvider(): array
4040
['en_US', 0, 1],
4141
['en', 1, 0],
4242
['en_UK', 2, 1],
43-
['es-ES', 2, 1],
43+
['es-ES', 2, 2],
4444
9E88 ['pt-br', 0, 0],
4545
['pt_BR', 1, 0],
46-
['pt_BR', 2, 1],
47-
['pt', 0, 1],
46+
['pt_BR', 2, 2],
47+
['pt', 0, 0],
4848
['pt', 1, 0],
49-
['pt', 2, 1],
50-
['pt_PT', 0, 1],
49+
['pt', 2, 2],
50+
['pt', 1000000, 1],
51+
['pt_PT', 0, 2],
5152
['pt_PT', 1, 0],
52-
['pt_PT', 2, 1],
53+
['pt_PT', 2, 2],
54+
['pt_PT', 1000000, 1],
5355
['fr_FR', 0, 0],
5456
['fr', 1, 0],
55-
['fr', 2, 1],
57+
['fr', 2, 2],
58+
['fr', 1000000, 1],
5659
['ru', 0, 2],
5760
['ru', 1, 0],
5861
['ru', 2, 1],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
msgid "{0} apple"
2+
msgid_plural "{0} apples"
3+
msgstr[0] "{0} pomme"
4+
msgstr[1] "{0} de pommes"
5+
msgstr[2] "{0} pommes"
6+
7+
msgid "{0} banana"
8+
msgid_plural "{0} bananas"
9+
msgstr[0] "{0} banana fr"
10+
msgstr[1] "{0} bananas fr"

0 commit comments

Comments
 (0)
0