Merge pull request #7147 from cakephp/issue-7118

Fix incorrectly parsed mo file context.
This commit is contained in:
José Lorenzo Rodríguez 2015-08-02 11:30:46 +02:00
commit b89ac18e55
3 changed files with 22 additions and 2 deletions

View file

@ -497,6 +497,9 @@ class I18n {
$msgid = substr($data, $r["offs"], $r["len"]);
unset($msgid_plural);
if (strpos($msgid, "\x04") !== false) {
list($context, $msgid) = explode("\x04", $msgid);
}
if (strpos($msgid, "\000")) {
list($msgid, $msgid_plural) = explode("\000", $msgid);
}
@ -508,9 +511,10 @@ class I18n {
}
if ($msgid != '') {
$msgstr = array($context => $msgstr);
$translations[$msgid][$context] = $msgstr;
} else {
$translations[$msgid] = $msgstr;
}
$translations[$msgid] = $msgstr;
if (isset($msgid_plural)) {
$translations[$msgid_plural] =& $translations[$msgid];

View file

@ -2040,6 +2040,22 @@ class I18nTest extends CakeTestCase {
$this->assertSame("saldo", __x('money', 'balance'));
}
/**
* Test basic context support using mo files.
*
* @return void
*/
public function testContextMoFile() {
Configure::write('Config.language', 'nld_mo');
$this->assertSame("brief", __x('mail', 'letter'));
$this->assertSame("letter", __x('character', 'letter'));
$this->assertSame("bal", __x('spherical object', 'ball'));
$this->assertSame("danspartij", __x('social gathering', 'ball'));
$this->assertSame("balans", __('balance'));
$this->assertSame("saldo", __x('money', 'balance'));
}
/**
* Singular method
*