mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
"Adding additional tests for I18n class.
Removed unused code from the class. Fixed use of invalid translations in a po file" git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6907 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
926b88a53a
commit
10d555d5e2
3 changed files with 174 additions and 4 deletions
|
@ -122,10 +122,11 @@ class I18n extends Object {
|
|||
}
|
||||
|
||||
$language = Configure::read('Config.language');
|
||||
if ($language === null && !empty($_SESSION['Config']['language'])) {
|
||||
if (!empty($_SESSION['Config']['language'])) {
|
||||
$language = $_SESSION['Config']['language'];
|
||||
}
|
||||
$_this =& I18n::getInstance();
|
||||
|
||||
if (($_this->__lang && $_this->__lang !== $language) || !$_this->__lang) {
|
||||
$lang = $_this->l10n->get($language);
|
||||
$_this->__lang = $lang;
|
||||
|
@ -310,7 +311,6 @@ class I18n extends Object {
|
|||
}
|
||||
return 2;
|
||||
}
|
||||
return $n;
|
||||
}
|
||||
/**
|
||||
* Binds the given domain to a file in the specified directory.
|
||||
|
@ -485,9 +485,12 @@ class I18n extends Object {
|
|||
$translations[$translationKey][$plural] = "";
|
||||
$type = 6;
|
||||
} elseif (preg_match("/^\"(.*)\"$/i", $line, $regs) && $type == 6 && $translationKey) {
|
||||
$translations[$translationKey][$plural] .= stripcslashes($regs[1]);
|
||||
unset($translations[$translationKey]);
|
||||
$type = 0;
|
||||
$translationKey = "";
|
||||
$plural = 0;
|
||||
} elseif (preg_match("/msgstr[[:space:]]+\"(.+)\"$/i", $line, $regs) && $type == 2 && !$translationKey) {
|
||||
$header = stripcslashes($regs[1]);
|
||||
$header .= stripcslashes($regs[1]);
|
||||
$type = 5;
|
||||
} elseif (preg_match("/msgstr[[:space:]]+\"\"$/i", $line, $regs) && !$translationKey) {
|
||||
$header = "";
|
||||
|
|
|
@ -1600,6 +1600,102 @@ class I18nTest extends UnitTestCase {
|
|||
|
||||
}
|
||||
|
||||
function testSetLanguageWithSession () {
|
||||
$_SESSION['Config']['language'] = 'po';
|
||||
$singular = $this->__Singular();
|
||||
$this->assertEqual('Po (translated)', $singular);
|
||||
|
||||
$plurals = $this->__Plural();
|
||||
$this->assertTrue(in_array('0 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('1 is 1 (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('2 is 2-4 (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('3 is 2-4 (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('4 is 2-4 (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('5 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('6 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('7 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('8 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('9 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('10 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('11 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('12 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('13 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('14 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('15 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('16 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('17 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('18 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('19 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('20 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('21 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('22 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('23 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('24 everything else (po translated)', $plurals));
|
||||
$this->assertTrue(in_array('25 everything else (po translated)', $plurals));
|
||||
unset($_SESSION['Config']['language']);
|
||||
}
|
||||
|
||||
function testNoCoreTranslation () {
|
||||
Configure::write('Config.language', 'po');
|
||||
$singular = $this->__Singular();
|
||||
$this->assertEqual('Po (translated)', $singular);
|
||||
|
||||
$coreSingular = $this->__singularFromCore();
|
||||
$this->assertNotEqual('Po (from core translated)', $coreSingular);
|
||||
|
||||
$corePlurals = $this->__pluralFromCore();
|
||||
$this->assertFalse(in_array('0 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('1 is 1 (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('2 is 2-4 (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('3 is 2-4 (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('4 is 2-4 (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('5 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('6 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('7 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('8 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('9 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('10 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('11 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('12 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('13 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('14 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('15 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('16 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('17 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('18 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('19 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('20 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('21 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('22 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('23 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('24 everything else (from core translated)', $corePlurals));
|
||||
$this->assertFalse(in_array('25 everything else (from core translated)', $corePlurals));
|
||||
}
|
||||
|
||||
function testPoMultipleLineTranslation () {
|
||||
Configure::write('Config.language', 'po');
|
||||
$string = <<<EOD
|
||||
This is a multiline translation
|
||||
broken up over multiple lines.
|
||||
This is the third line.
|
||||
This is the forth line.
|
||||
EOD;
|
||||
$result = __($string, true);
|
||||
$expected = <<<EOD
|
||||
This is a multiline translation
|
||||
broken up over multiple lines.
|
||||
This is the third line.
|
||||
This is the forth line. (translated)
|
||||
EOD;
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
function testPoNoTranslationNeeded () {
|
||||
Configure::write('Config.language', 'po');
|
||||
$result = __('No Translation needed', true);
|
||||
$this->assertEqual($result, 'No Translation needed');
|
||||
}
|
||||
|
||||
function __Singular() {
|
||||
$singular = __('Plural Rule 1', true);
|
||||
return $singular;
|
||||
|
|
71
cake/tests/test_app/locale/po/LC_MESSAGES/default.po
Normal file
71
cake/tests/test_app/locale/po/LC_MESSAGES/default.po
Normal file
|
@ -0,0 +1,71 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: CakePHP Testsuite\n"
|
||||
"POT-Creation-Date: 2008-05-15 02:51-0700\n"
|
||||
"PO-Revision-Date: \n"
|
||||
"Last-Translator: CakePHP I18N & I10N Team <i10n.cakephp@gmail.com>\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=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
|
||||
"X-Poedit-Language: Three Forms of Plurals\n"
|
||||
"X-Poedit-SourceCharset: utf-8\n"
|
||||
msgid ""
|
||||
msgstr "header"
|
||||
|
||||
msgid "Plural Rule 1"
|
||||
msgstr "Po (translated)"
|
||||
|
||||
msgid "%d = 1"
|
||||
msgid_plural "%d = 0 or > 1"
|
||||
msgstr[0] "%d is 1 (po translated)"
|
||||
msgstr[1] "%d is 2-4 (po translated)"
|
||||
msgstr[2] "%d everything else (po translated)"
|
||||
|
||||
msgid "This is a multiline translation\n"
|
||||
"broken up over multiple lines.\n"
|
||||
"This is the third line.\n"
|
||||
"This is the forth line."
|
||||
msgstr "This is a multiline translation\n"
|
||||
"broken up over multiple lines.\n"
|
||||
"This is the third line.\n"
|
||||
"This is the forth line. (translated)"
|
||||
|
||||
msgid "No Translation needed"
|
||||
msgstr ""
|
||||
|
||||
msgid "test"
|
||||
msgid_plural "tests"
|
||||
msgstr[0] "test translated"
|
||||
msgstr[1] "test translated"
|
||||
msgstr[2] ""
|
||||
msgstr[3] ""
|
||||
|
||||
# Invalid
|
||||
msgid "invalid "
|
||||
"second line"
|
||||
msgid_plural "invalids "
|
||||
"second line
|
||||
msgstr[0] "v "
|
||||
"second line"
|
||||
msgstr[1] "vs "
|
||||
"second line"
|
||||
|
||||
# Invalid
|
||||
msgid "v"
|
||||
msgid_plural "vs "
|
||||
msgstr[0] "v"
|
||||
"second line"
|
||||
msgstr[1] "vs "
|
||||
"second line"
|
||||
|
||||
msgid "invalid \n"
|
||||
"second line"
|
||||
msgid_plural "invalids \n"
|
||||
"second line
|
||||
msgstr[0] "v \n"
|
||||
"second line"
|
||||
msgstr[1] "vs \n"
|
||||
"second line"
|
||||
|
Loading…
Reference in a new issue