Use correct context when parsing MO file.

This commit is contained in:
Edgaras Janušauskas 2015-12-18 12:59:00 +02:00
parent 0668cc6ff1
commit 4101a96a95
4 changed files with 9 additions and 2 deletions

View file

@ -478,6 +478,7 @@ class I18n {
*
* @param string $filename Binary .mo file to load
* @return mixed Array of translations on success or false on failure
* @link https://www.gnu.org/software/gettext/manual/html_node/MO-Files.html
*/
public static function loadMo($filename) {
$translations = false;
@ -486,7 +487,6 @@ class I18n {
// Binary files extracted makes non-standard local variables
if ($data = file_get_contents($filename)) {
$translations = array();
$context = null;
$header = substr($data, 0, 20);
$header = unpack('L1magic/L1version/L1count/L1o_msg/L1o_trn', $header);
extract($header);
@ -496,6 +496,7 @@ class I18n {
$r = unpack("L1len/L1offs", substr($data, $o_msg + $n * 8, 8));
$msgid = substr($data, $r["offs"], $r["len"]);
unset($msgid_plural);
$context = null;
if (strpos($msgid, "\x04") !== false) {
list($context, $msgid) = explode("\x04", $msgid);

View file

@ -2054,6 +2054,9 @@ class I18nTest extends CakeTestCase {
$this->assertSame("danspartij", __x('social gathering', 'ball'));
$this->assertSame("balans", __('balance'));
$this->assertSame("saldo", __x('money', 'balance'));
// MO file is sorted by msgid, 'zoo' should be last
$this->assertSame("dierentuin", __('zoo'));
}
/**

View file

@ -26,4 +26,7 @@ msgstr "balans"
msgctxt "money"
msgid "balance"
msgstr "saldo"
msgstr "saldo"
msgid "zoo"
msgstr "dierentuin"