diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 253081ba6a7..3cc00290b94 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -311,6 +311,7 @@ public static function domains() { * @param string $header Type * @param int $n Number * @return int plural match + * @see */ protected function _pluralGuess($header, $n) { if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) { @@ -351,7 +352,15 @@ protected function _pluralGuess($header, $n) { } } elseif (strpos($header, "plurals=5")) { return $n == 1 ? 0 : ($n == 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4))); + } elseif (strpos($header, "plurals=6")) { + return $n == 0 ? 0 : + ($n == 1 ? 1 : + ($n == 2 ? 2 : + ($n % 100 >= 3 && $n % 100 <= 10 ? 3 : + ($n % 100 >= 11 ? 4 : 5)))); } + + return 0; } /** diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index 35ff4b05614..ded12231c91 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -1512,6 +1512,127 @@ public function assertRulesFourteen() { $this->assertTrue(in_array('25 everything else (from core translated)', $corePlurals)); } +/** + * testMoRulesFifteen method + * + * @return void + */ + public function testMoRulesFifteen() { + Configure::write('Config.language', 'rule_15_mo'); + $this->assertRulesFifteen(); + } + +/** + * testPoRulesFifteen method + * + * @return void + */ + public function testPoRulesFifteen() { + Configure::write('Config.language', 'rule_15_po'); + $this->assertRulesFifteen(); + } + +/** + * Assertions for plural rules fifteen + * + * @return void + */ + public function assertRulesFifteen() { + $singular = $this->_singular(); + $this->assertEquals('Plural Rule 15 (translated)', $singular); + + $plurals = $this->_plural(111); + $this->assertTrue(in_array('0 is 0 (translated)', $plurals)); + $this->assertTrue(in_array('1 is 1 (translated)', $plurals)); + $this->assertTrue(in_array('2 is 2 (translated)', $plurals)); + $this->assertTrue(in_array('3 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('4 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('5 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('6 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('7 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('8 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('9 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('10 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('11 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('12 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('13 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('14 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('15 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('16 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('17 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('18 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('19 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('20 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('31 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('42 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('53 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('64 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('75 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('86 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('97 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('98 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('99 ends with 11-99 (translated)', $plurals)); + $this->assertTrue(in_array('100 everything else (translated)', $plurals)); + $this->assertTrue(in_array('101 everything else (translated)', $plurals)); + $this->assertTrue(in_array('102 everything else (translated)', $plurals)); + $this->assertTrue(in_array('103 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('104 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('105 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('106 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('107 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('108 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('109 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('110 ends with 03-10 (translated)', $plurals)); + $this->assertTrue(in_array('111 ends with 11-99 (translated)', $plurals)); + + $coreSingular = $this->_singularFromCore(); + $this->assertEquals('Plural Rule 15 (from core translated)', $coreSingular); + + $corePlurals = $this->_pluralFromCore(111); + $this->assertTrue(in_array('0 is 0 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('1 is 1 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('2 is 2 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('3 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('4 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('5 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('6 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('7 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('8 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('9 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('10 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('11 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('12 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('13 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('14 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('15 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('16 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('17 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('18 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('19 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('20 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('31 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('42 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('53 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('64 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('75 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('86 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('97 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('98 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('99 ends with 11-99 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('100 everything else (from core translated)', $corePlurals)); + $this->assertTrue(in_array('101 everything else (from core translated)', $corePlurals)); + $this->assertTrue(in_array('102 everything else (from core translated)', $corePlurals)); + $this->assertTrue(in_array('103 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('104 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('105 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('106 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('107 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('108 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('109 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('110 ends with 03-10 (from core translated)', $corePlurals)); + $this->assertTrue(in_array('111 ends with 11-99 (from core translated)', $corePlurals)); + } + /** * testSetLanguageWithSession method * @@ -1948,11 +2069,12 @@ protected function _singular() { /** * Plural method * + * @param int $upTo For numbers upto (default to 25) * @return void */ - protected function _plural() { + protected function _plural($upTo = 25) { $plurals = array(); - for ($number = 0; $number <= 25; $number++) { + for ($number = 0; $number <= $upTo; $number++) { $plurals[] = sprintf(__n('%d = 1', '%d = 0 or > 1', (float)$number), (float)$number); } return $plurals; @@ -1971,11 +2093,12 @@ protected function _singularFromCore() { /** * pluralFromCore method * + * @param int $upTo For numbers upto (default to 25) * @return void */ - protected function _pluralFromCore() { + protected function _pluralFromCore($upTo = 25) { $plurals = array(); - for ($number = 0; $number <= 25; $number++) { + for ($number = 0; $number <= $upTo; $number++) { $plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number), (float)$number); } return $plurals; diff --git a/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo b/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo new file mode 100644 index 00000000000..54ae1eeb2fc Binary files /dev/null and b/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo differ diff --git a/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo b/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo new file mode 100644 index 00000000000..aa402fe9d4f Binary files /dev/null and b/lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo differ diff --git a/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po new file mode 100644 index 00000000000..1f8d1fe9cb3 --- /dev/null +++ b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po @@ -0,0 +1,25 @@ +msgid "" +msgstr "" +"Project-Id-Version: CakePHP Testsuite\n" +"POT-Creation-Date: 2014-12-06 19:20-0300\n" +"PO-Revision-Date: \n" +"Language-Team: CakePHP I18N & I10N Team \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" +"X-Poedit-Language: Six Forms of Plurals\n" +"X-Poedit-SourceCharset: utf-8\n" + +msgid "Plural Rule 1 (from core)" +msgstr "Plural Rule 15 (from core translated)" + +msgid "%d = 1 (from core)" +msgid_plural "%d = 0 or > 1 (from core)" +msgstr[0] "%d is 0 (from core translated)" +msgstr[1] "%d is 1 (from core translated)" +msgstr[2] "%d is 2 (from core translated)" +msgstr[3] "%d ends with 03-10 (from core translated)" +msgstr[4] "%d ends with 11-99 (from core translated)" +msgstr[5] "%d everything else (from core translated)" + diff --git a/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po new file mode 100644 index 00000000000..3a299880417 --- /dev/null +++ b/lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/default.po @@ -0,0 +1,25 @@ +msgid "" +msgstr "" +"Project-Id-Version: CakePHP Testsuite\n" +"POT-Creation-Date: 2014-12-06 19:20-0300\n" +"PO-Revision-Date: \n" +"Language-Team: CakePHP I18N & I10N Team \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;\n" +"X-Poedit-Language: Six Forms of Plurals\n" +"X-Poedit-SourceCharset: utf-8\n" + +msgid "Plural Rule 1" +msgstr "Plural Rule 15 (translated)" + +msgid "%d = 1" +msgid_plural "%d = 0 or > 1" +msgstr[0] "%d is 0 (translated)" +msgstr[1] "%d is 1 (translated)" +msgstr[2] "%d is 2 (translated)" +msgstr[3] "%d ends with 03-10 (translated)" +msgstr[4] "%d ends with 11-99 (translated)" +msgstr[5] "%d everything else (translated)" +