Skip to content
Permalink
Browse files

Use correct context when parsing MO file.

  • Loading branch information...
garas committed Dec 18, 2015
1 parent 0668cc6 commit 4101a96a95048396df7da149eb9da5dfe6568eb7
@@ -478,6 +478,7 @@ protected function _bindTextDomain($domain) {
*
* @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 @@ public static function loadMo($filename) {
// 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 @@ public static function loadMo($filename) {
$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);
@@ -2054,6 +2054,9 @@ public function testContextMoFile() {
$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'));
}
/**
@@ -26,4 +26,7 @@ msgstr "balans"

msgctxt "money"
msgid "balance"
msgstr "saldo"
msgstr "saldo"

msgid "zoo"
msgstr "dierentuin"
Binary file not shown.

0 comments on commit 4101a96

Please sign in to comment.
You can’t perform that action at this time.