mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #5360 from ADmad/i18n-arabic
Fix plural calculation for Arabic
This commit is contained in:
commit
1a1583a832
6 changed files with 187 additions and 4 deletions
|
@ -311,6 +311,8 @@ class I18n {
|
|||
* @param string $header Type
|
||||
* @param int $n Number
|
||||
* @return int plural match
|
||||
* @link http://localization-guide.readthedocs.org/en/latest/l10n/pluralforms.html
|
||||
* @link https://developer.mozilla.org/en-US/docs/Mozilla/Localization/Localization_and_Plurals#List_of_Plural_Rules
|
||||
*/
|
||||
protected function _pluralGuess($header, $n) {
|
||||
if (!is_string($header) || $header === "nplurals=1;plural=0;" || !isset($header[0])) {
|
||||
|
@ -351,7 +353,15 @@ class I18n {
|
|||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1512,6 +1512,127 @@ class I18nTest extends CakeTestCase {
|
|||
$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 @@ class I18nTest extends CakeTestCase {
|
|||
/**
|
||||
* 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 @@ class I18nTest extends CakeTestCase {
|
|||
/**
|
||||
* 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;
|
||||
|
|
BIN
lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo
Normal file
BIN
lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/core.mo
Normal file
Binary file not shown.
BIN
lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo
Normal file
BIN
lib/Cake/Test/test_app/Locale/rule_15_mo/LC_MESSAGES/default.mo
Normal file
Binary file not shown.
25
lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po
Normal file
25
lib/Cake/Test/test_app/Locale/rule_15_po/LC_MESSAGES/core.po
Normal file
|
@ -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 <i10n.cakephp@gmail.com>\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)"
|
||||
|
|
@ -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 <i10n.cakephp@gmail.com>\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)"
|
||||
|
Loading…
Reference in a new issue