Commit f584ef47b6e6c76546f43caf29931e2c8e573682

Authored by Megan Watson
1 parent 25100876

Changed reg ex's to work on windows

PT: 1698935
Jira: KTS-4517

Committed by: Megan Watson
Reviewed by: Charl Mert
thirdparty/pear/File/Gettext/PO.php
... ... @@ -3,7 +3,7 @@
3 3  
4 4 /**
5 5 * File::Gettext
6   - *
  6 + *
7 7 * PHP versions 4 and 5
8 8 *
9 9 * @category FileFormats
... ... @@ -20,11 +20,11 @@
20 20 */
21 21 require_once 'File/Gettext.php';
22 22  
23   -/**
  23 +/**
24 24 * File_Gettext_PO
25 25 *
26 26 * GNU PO file reader and writer.
27   - *
  27 + *
28 28 * @author Michael Wallner <mike@php.net>
29 29 * @version $Revision$
30 30 * @access public
... ... @@ -55,7 +55,7 @@ class File_Gettext_PO extends File_Gettext
55 55 if (!isset($file)) {
56 56 $file = $this->file;
57 57 }
58   -
  58 +
59 59 // load file
60 60 if (!$contents = @file($file)) {
61 61 return parent::raiseError($php_errormsg . ' ' . $file);
... ... @@ -65,6 +65,35 @@ class File_Gettext_PO extends File_Gettext
65 65 $aMatches = array();
66 66  
67 67 foreach ($contents as $line) {
  68 + /*
  69 + Replaced the regular expressions to get translations working on windows.
  70 + */
  71 + if (preg_match('/^msgid(.*)$/', $line, $aMatches)) {
  72 + if ($msgid) {
  73 + $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
  74 + }
  75 + $msgid = trim($aMatches[1]);
  76 + $msgid = substr($msgid, 1, strlen($msgid) - 2);
  77 + $msgstr = "";
  78 + $msgstr_started = false;
  79 + }
  80 + //#^msgstr "(.*)"$#
  81 + if (preg_match('/^msgstr(.*)$/', $line, $aMatches)) {
  82 + $msgstr = trim($aMatches[1]);
  83 + $msgstr = substr($msgstr, 1, strlen($msgstr) - 2);
  84 + $msgstr_started = true;
  85 + }
  86 + //#^"(.*)"$#
  87 + if (preg_match('/^"(.*)"$/', $line, $aMatches)) {
  88 + if ($msgstr_started) {
  89 + $tmp = trim($aMatches[1]);
  90 + $msgstr .= substr($tmp, 1, strlen($tmp) - 2);
  91 + } else {
  92 + $tmp = trim($aMatches[1]);
  93 + $msgid .= substr($tmp, 1, strlen($tmp) - 2);
  94 + }
  95 + }
  96 + /* Original code
68 97 if (preg_match('#^msgid "(.*)"$#', $line, $aMatches)) {
69 98 if ($msgid) {
70 99 $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
... ... @@ -84,6 +113,7 @@ class File_Gettext_PO extends File_Gettext
84 113 $msgid .= $aMatches[1];
85 114 }
86 115 }
  116 + */
87 117 }
88 118 if ($msgid) {
89 119 $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
... ... @@ -94,10 +124,10 @@ class File_Gettext_PO extends File_Gettext
94 124 $this->meta = parent::meta2array($this->strings['']);
95 125 unset($this->strings['']);
96 126 }
97   -
  127 +
98 128 return true;
99 129 }
100   -
  130 +
101 131 /**
102 132 * Save PO file
103 133 *
... ... @@ -110,7 +140,7 @@ class File_Gettext_PO extends File_Gettext
110 140 if (!isset($file)) {
111 141 $file = $this->file;
112 142 }
113   -
  143 +
114 144 // open PO file
115 145 if (!is_resource($fh = @fopen($file, 'w'))) {
116 146 return parent::raiseError($php_errormsg . ' ' . $file);
... ... @@ -120,7 +150,7 @@ class File_Gettext_PO extends File_Gettext
120 150 @fclose($fh);
121 151 return parent::raiseError($php_errmsg . ' ' . $file);
122 152 }
123   -
  153 +
124 154 // write meta info
125 155 if (count($this->meta)) {
126 156 $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n";
... ... @@ -136,7 +166,7 @@ class File_Gettext_PO extends File_Gettext
136 166 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n"
137 167 );
138 168 }
139   -
  169 +
140 170 //done
141 171 @flock($fh, LOCK_UN);
142 172 @fclose($fh);
... ...