diff --git a/lib/Cake/I18n/I18n.php b/lib/Cake/I18n/I18n.php index 1ce5aae48..1b79fa2f8 100644 --- a/lib/Cake/I18n/I18n.php +++ b/lib/Cake/I18n/I18n.php @@ -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); diff --git a/lib/Cake/Test/Case/I18n/I18nTest.php b/lib/Cake/Test/Case/I18n/I18nTest.php index faac0e069..51ab95259 100644 --- a/lib/Cake/Test/Case/I18n/I18nTest.php +++ b/lib/Cake/Test/Case/I18n/I18nTest.php @@ -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')); } /** diff --git a/lib/Cake/Test/test_app/Locale/nld/LC_MESSAGES/default.po b/lib/Cake/Test/test_app/Locale/nld/LC_MESSAGES/default.po index dfee4f93e..9bfcc2e4b 100644 --- a/lib/Cake/Test/test_app/Locale/nld/LC_MESSAGES/default.po +++ b/lib/Cake/Test/test_app/Locale/nld/LC_MESSAGES/default.po @@ -26,4 +26,7 @@ msgstr "balans" msgctxt "money" msgid "balance" -msgstr "saldo" \ No newline at end of file +msgstr "saldo" + +msgid "zoo" +msgstr "dierentuin" diff --git a/lib/Cake/Test/test_app/Locale/nld_mo/LC_MESSAGES/default.mo b/lib/Cake/Test/test_app/Locale/nld_mo/LC_MESSAGES/default.mo index bb89fa6e9..83a8e6273 100644 Binary files a/lib/Cake/Test/test_app/Locale/nld_mo/LC_MESSAGES/default.mo and b/lib/Cake/Test/test_app/Locale/nld_mo/LC_MESSAGES/default.mo differ