From 4101a96a95048396df7da149eb9da5dfe6568eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgaras=20Janu=C5=A1auskas?= Date: Fri, 18 Dec 2015 12:59:00 +0200 Subject: [PATCH] Use correct context when parsing MO file. --- lib/Cake/I18n/I18n.php | 3 ++- lib/Cake/Test/Case/I18n/I18nTest.php | 3 +++ .../test_app/Locale/nld/LC_MESSAGES/default.po | 5 ++++- .../Locale/nld_mo/LC_MESSAGES/default.mo | Bin 335 -> 392 bytes 4 files changed, 9 insertions(+), 2 deletions(-) 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 bb89fa6e9ae1b1f1848449c9ce986d282aa6232d..83a8e6273c556f0fe297ccf839b763bcf1ba87ba 100644 GIT binary patch delta 208 zcmX@l)WJMKq@J6Bfng31vjg!7AZ7vL3qULZ#8-h>7>M5iF)t7^F)}cS0%-v#tp=o- zfqWYv%?6|$pnP{A%?IRr18I=HC?L%Wq%(jt7m&^a(ja}6j0{F#fm)yd6Hox;2oL~r o!3J`Gc@Rf|3;=0jm^iDPxhg+@vLK@!cS>ezQEFaEX=WY+00cJ^A^-pY delta 149 zcmeBRKF>5kq@Do?=70zw0MYC~JQs*rfOshoO91gIAQlGV!$8an#MgmX6o{Wf>EA#a z1Oyow7}$Wc5RhgD(vm=$4@k=bX^=i0Ak7M-t$;Kakal1MS_e|-%{cLB`DA-WI{