diff --git a/cake/libs/i18n.php b/cake/libs/i18n.php index 6836193b2..36af0284d 100644 --- a/cake/libs/i18n.php +++ b/cake/libs/i18n.php @@ -213,31 +213,31 @@ class I18n extends Object { if (strpos($header, "plurals=3")) { if (strpos($header, "100!=11")) { if (strpos($header, "10<=4")) { - return $n % 10 === 1 && $n % 100 !== 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); + return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); } elseif (strpos($header, "100<10")) { - return $n % 10 === 1 && $n % 100 !== 11 ? 0 : ($n % 10 >= 2 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); + return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n % 10 >= 2 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); } return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n != 0 ? 1 : 2); } elseif (strpos($header, "n==2")) { - return $n === 1 ? 0 : ($n === 2 ? 1 : 2); + return $n == 1 ? 0 : ($n == 2 ? 1 : 2); } elseif (strpos($header, "n==0")) { - return $n === 1 ? 0 : ($n === 0 || ($n % 100 > 0 && $n % 100 < 20) ? 1 : 2); + return $n == 1 ? 0 : ($n == 0 || ($n % 100 > 0 && $n % 100 < 20) ? 1 : 2); } elseif (strpos($header, "n>=2")) { - return $n === 1 ? 0 : ($n >= 2 && $n <= 4 ? 1 : 2); + return $n == 1 ? 0 : ($n >= 2 && $n <= 4 ? 1 : 2); } elseif (strpos($header, "10>=2")) { - return $n === 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); + return $n == 1 ? 0 : ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2); } - return $n % 10 === 1 ? 0 : ($n % 10 === 2 ? 1 : 2); + return $n % 10 == 1 ? 0 : ($n % 10 == 2 ? 1 : 2); } elseif (strpos($header, "plurals=4")) { if (strpos($header, "100==2")) { - return $n % 100 === 1 ? 0 : ($n % 100 === 2 ? 1 : ($n % 100 === 3 || $n % 100 === 4 ? 2 : 3)); + return $n % 100 == 1 ? 0 : ($n % 100 == 2 ? 1 : ($n % 100 == 3 || $n % 100 == 4 ? 2 : 3)); } elseif (strpos($header, "n>=3")) { - return $n === 1 ? 0 : ($n === 2 ? 1 : ($n == 0 || ($n >= 3 && $n <= 10) ? 2 : 3)); + return $n == 1 ? 0 : ($n == 2 ? 1 : ($n == 0 || ($n >= 3 && $n <= 10) ? 2 : 3)); } elseif (strpos($header, "100>=1")) { - return $n === 1 ? 0 : ($n == 0 || ($n % 100 >= 1 && $n % 100 <= 10) ? 1 : ($n % 100 >= 11 && $n % 100 <= 20 ? 2 : 3)); + return $n == 1 ? 0 : ($n == 0 || ($n % 100 >= 1 && $n % 100 <= 10) ? 1 : ($n % 100 >= 11 && $n % 100 <= 20 ? 2 : 3)); } } elseif (strpos($header, "plurals=5")) { - return $n === 1 ? 0 : ($n === 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4))); + return $n == 1 ? 0 : ($n == 2 ? 1 : ($n >= 3 && $n <= 6 ? 2 : ($n >= 7 && $n <= 10 ? 3 : 4))); } } /** diff --git a/cake/tests/cases/libs/i18n.test.php b/cake/tests/cases/libs/i18n.test.php index 3bedf61fa..d10a61f73 100644 --- a/cake/tests/cases/libs/i18n.test.php +++ b/cake/tests/cases/libs/i18n.test.php @@ -2470,16 +2470,19 @@ class I18nTest extends CakeTestCase { $this->assertEqual(__('this is a "quoted string"', true), $expected); } function testFloatValue() { - Configure::write('Config.language', 'rule_3_po'); + Configure::write('Config.language', 'rule_9_po'); $result = __n('%d = 1', '%d = 0 or > 1', (float)1, true); - $expected = '%d is 1 (from core translated)'; + $expected = '%d is 1 (translated)'; + $this->assertEqual($result, $expected); $result = __n('%d = 1', '%d = 0 or > 1', (float)2, true); - $expected = "%d ends in 2-4, not 12-14 (from core translated)"; + $expected = "%d ends in 2-4, not 12-14 (translated)"; + $this->assertEqual($result, $expected); $result = __n('%d = 1', '%d = 0 or > 1', (float)5, true); - $expected = "%d everything else (from core translated)"; + $expected = "%d everything else (translated)"; + $this->assertEqual($result, $expected); } /** * Singular method @@ -2500,7 +2503,7 @@ class I18nTest extends CakeTestCase { function __domainPlural($domain = 'test_plugin') { $plurals = array(); for ($number = 0; $number <= 25; $number++) { - $plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', $number, true), $number ); + $plurals[] = sprintf(__dn($domain, '%d = 1', '%d = 0 or > 1', (float)$number, true), (float)$number ); } return $plurals; } @@ -2523,7 +2526,7 @@ class I18nTest extends CakeTestCase { function __plural() { $plurals = array(); for ($number = 0; $number <= 25; $number++) { - $plurals[] = sprintf(__n('%d = 1', '%d = 0 or > 1', $number, true), $number ); + $plurals[] = sprintf(__n('%d = 1', '%d = 0 or > 1', (float)$number, true), (float)$number ); } return $plurals; } @@ -2546,7 +2549,7 @@ class I18nTest extends CakeTestCase { function __pluralFromCore() { $plurals = array(); for ($number = 0; $number <= 25; $number++) { - $plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', $number, true), $number ); + $plurals[] = sprintf(__n('%d = 1 (from core)', '%d = 0 or > 1 (from core)', (float)$number, true), (float)$number ); } return $plurals; }