Commit b416e848e710013edc5ab4ece571dd934f3dbed4

Authored by Neil Blakey-Milner
1 parent 1cad081d

Fix a problem dealing with PO files when the msgstr contains an escape

quote - it previously prematurely ended the msgstr.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5350 c91229c3-7414-0410-bfa2-8a42b809f60b
thirdparty/pear/File/Gettext/PO.php
@@ -60,29 +60,35 @@ class File_Gettext_PO extends File_Gettext @@ -60,29 +60,35 @@ class File_Gettext_PO extends File_Gettext
60 if (!$contents = @file($file)) { 60 if (!$contents = @file($file)) {
61 return parent::raiseError($php_errormsg . ' ' . $file); 61 return parent::raiseError($php_errormsg . ' ' . $file);
62 } 62 }
63 - $contents = implode('', $contents);  
64 -  
65 - // match all msgid/msgstr entries  
66 - $matched = preg_match_all(  
67 - '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' .  
68 - '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/',  
69 - $contents, $matches  
70 - );  
71 - unset($contents);  
72 -  
73 - if (!$matched) {  
74 - return parent::raiseError('No msgid/msgstr entries found'); 63 +
  64 + $msgid = null;
  65 + $aMatches = array();
  66 +
  67 + foreach ($contents as $line) {
  68 + if (preg_match('#^msgid "(.*)"$#', $line, $aMatches)) {
  69 + if ($msgid) {
  70 + $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
  71 + }
  72 + $msgid = $aMatches[1];
  73 + $msgstr = "";
  74 + $msgstr_started = false;
  75 + }
  76 + if (preg_match('#^msgstr "(.*)"$#', $line, $aMatches)) {
  77 + $msgstr = $aMatches[1];
  78 + $msgstr_started = true;
  79 + }
  80 + if (preg_match('#^"(.*)"$#', $line, $aMatches)) {
  81 + if ($msgstr_started) {
  82 + $msgstr .= $aMatches[1];
  83 + } else {
  84 + $msgid .= $aMatches[1];
  85 + }
  86 + }
75 } 87 }
76 -  
77 - // get all msgids and msgtrs  
78 - for ($i = 0; $i < $matched; $i++) {  
79 - $msgid = preg_replace(  
80 - '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]);  
81 - $msgstr= preg_replace(  
82 - '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); 88 + if ($msgid) {
83 $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); 89 $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
84 } 90 }
85 - 91 +
86 // check for meta info 92 // check for meta info
87 if (isset($this->strings[''])) { 93 if (isset($this->strings[''])) {
88 $this->meta = parent::meta2array($this->strings['']); 94 $this->meta = parent::meta2array($this->strings['']);