From b416e848e710013edc5ab4ece571dd934f3dbed4 Mon Sep 17 00:00:00 2001 From: Neil Blakey-Milner Date: Wed, 26 Apr 2006 09:18:04 +0000 Subject: [PATCH] Fix a problem dealing with PO files when the msgstr contains an escape quote - it previously prematurely ended the msgstr. --- thirdparty/pear/File/Gettext/PO.php | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/thirdparty/pear/File/Gettext/PO.php b/thirdparty/pear/File/Gettext/PO.php index d2fbfb0..6f4c1eb 100644 --- a/thirdparty/pear/File/Gettext/PO.php +++ b/thirdparty/pear/File/Gettext/PO.php @@ -60,29 +60,35 @@ class File_Gettext_PO extends File_Gettext if (!$contents = @file($file)) { return parent::raiseError($php_errormsg . ' ' . $file); } - $contents = implode('', $contents); - - // match all msgid/msgstr entries - $matched = preg_match_all( - '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . - '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', - $contents, $matches - ); - unset($contents); - - if (!$matched) { - return parent::raiseError('No msgid/msgstr entries found'); + + $msgid = null; + $aMatches = array(); + + foreach ($contents as $line) { + if (preg_match('#^msgid "(.*)"$#', $line, $aMatches)) { + if ($msgid) { + $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); + } + $msgid = $aMatches[1]; + $msgstr = ""; + $msgstr_started = false; + } + if (preg_match('#^msgstr "(.*)"$#', $line, $aMatches)) { + $msgstr = $aMatches[1]; + $msgstr_started = true; + } + if (preg_match('#^"(.*)"$#', $line, $aMatches)) { + if ($msgstr_started) { + $msgstr .= $aMatches[1]; + } else { + $msgid .= $aMatches[1]; + } + } } - - // get all msgids and msgtrs - for ($i = 0; $i < $matched; $i++) { - $msgid = preg_replace( - '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); - $msgstr= preg_replace( - '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); + if ($msgid) { $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); } - + // check for meta info if (isset($this->strings[''])) { $this->meta = parent::meta2array($this->strings['']); -- libgit2 0.21.4