Commit f584ef47b6e6c76546f43caf29931e2c8e573682
1 parent
25100876
Changed reg ex's to work on windows
PT: 1698935 Jira: KTS-4517 Committed by: Megan Watson Reviewed by: Charl Mert
Showing
1 changed file
with
39 additions
and
9 deletions
thirdparty/pear/File/Gettext/PO.php
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | 3 | ||
| 4 | /** | 4 | /** |
| 5 | * File::Gettext | 5 | * File::Gettext |
| 6 | - * | 6 | + * |
| 7 | * PHP versions 4 and 5 | 7 | * PHP versions 4 and 5 |
| 8 | * | 8 | * |
| 9 | * @category FileFormats | 9 | * @category FileFormats |
| @@ -20,11 +20,11 @@ | @@ -20,11 +20,11 @@ | ||
| 20 | */ | 20 | */ |
| 21 | require_once 'File/Gettext.php'; | 21 | require_once 'File/Gettext.php'; |
| 22 | 22 | ||
| 23 | -/** | 23 | +/** |
| 24 | * File_Gettext_PO | 24 | * File_Gettext_PO |
| 25 | * | 25 | * |
| 26 | * GNU PO file reader and writer. | 26 | * GNU PO file reader and writer. |
| 27 | - * | 27 | + * |
| 28 | * @author Michael Wallner <mike@php.net> | 28 | * @author Michael Wallner <mike@php.net> |
| 29 | * @version $Revision$ | 29 | * @version $Revision$ |
| 30 | * @access public | 30 | * @access public |
| @@ -55,7 +55,7 @@ class File_Gettext_PO extends File_Gettext | @@ -55,7 +55,7 @@ class File_Gettext_PO extends File_Gettext | ||
| 55 | if (!isset($file)) { | 55 | if (!isset($file)) { |
| 56 | $file = $this->file; | 56 | $file = $this->file; |
| 57 | } | 57 | } |
| 58 | - | 58 | + |
| 59 | // load file | 59 | // load file |
| 60 | if (!$contents = @file($file)) { | 60 | if (!$contents = @file($file)) { |
| 61 | return parent::raiseError($php_errormsg . ' ' . $file); | 61 | return parent::raiseError($php_errormsg . ' ' . $file); |
| @@ -65,6 +65,35 @@ class File_Gettext_PO extends File_Gettext | @@ -65,6 +65,35 @@ class File_Gettext_PO extends File_Gettext | ||
| 65 | $aMatches = array(); | 65 | $aMatches = array(); |
| 66 | 66 | ||
| 67 | foreach ($contents as $line) { | 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 | if (preg_match('#^msgid "(.*)"$#', $line, $aMatches)) { | 97 | if (preg_match('#^msgid "(.*)"$#', $line, $aMatches)) { |
| 69 | if ($msgid) { | 98 | if ($msgid) { |
| 70 | $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); | 99 | $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
| @@ -84,6 +113,7 @@ class File_Gettext_PO extends File_Gettext | @@ -84,6 +113,7 @@ class File_Gettext_PO extends File_Gettext | ||
| 84 | $msgid .= $aMatches[1]; | 113 | $msgid .= $aMatches[1]; |
| 85 | } | 114 | } |
| 86 | } | 115 | } |
| 116 | + */ | ||
| 87 | } | 117 | } |
| 88 | if ($msgid) { | 118 | if ($msgid) { |
| 89 | $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); | 119 | $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
| @@ -94,10 +124,10 @@ class File_Gettext_PO extends File_Gettext | @@ -94,10 +124,10 @@ class File_Gettext_PO extends File_Gettext | ||
| 94 | $this->meta = parent::meta2array($this->strings['']); | 124 | $this->meta = parent::meta2array($this->strings['']); |
| 95 | unset($this->strings['']); | 125 | unset($this->strings['']); |
| 96 | } | 126 | } |
| 97 | - | 127 | + |
| 98 | return true; | 128 | return true; |
| 99 | } | 129 | } |
| 100 | - | 130 | + |
| 101 | /** | 131 | /** |
| 102 | * Save PO file | 132 | * Save PO file |
| 103 | * | 133 | * |
| @@ -110,7 +140,7 @@ class File_Gettext_PO extends File_Gettext | @@ -110,7 +140,7 @@ class File_Gettext_PO extends File_Gettext | ||
| 110 | if (!isset($file)) { | 140 | if (!isset($file)) { |
| 111 | $file = $this->file; | 141 | $file = $this->file; |
| 112 | } | 142 | } |
| 113 | - | 143 | + |
| 114 | // open PO file | 144 | // open PO file |
| 115 | if (!is_resource($fh = @fopen($file, 'w'))) { | 145 | if (!is_resource($fh = @fopen($file, 'w'))) { |
| 116 | return parent::raiseError($php_errormsg . ' ' . $file); | 146 | return parent::raiseError($php_errormsg . ' ' . $file); |
| @@ -120,7 +150,7 @@ class File_Gettext_PO extends File_Gettext | @@ -120,7 +150,7 @@ class File_Gettext_PO extends File_Gettext | ||
| 120 | @fclose($fh); | 150 | @fclose($fh); |
| 121 | return parent::raiseError($php_errmsg . ' ' . $file); | 151 | return parent::raiseError($php_errmsg . ' ' . $file); |
| 122 | } | 152 | } |
| 123 | - | 153 | + |
| 124 | // write meta info | 154 | // write meta info |
| 125 | if (count($this->meta)) { | 155 | if (count($this->meta)) { |
| 126 | $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; | 156 | $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; |
| @@ -136,7 +166,7 @@ class File_Gettext_PO extends File_Gettext | @@ -136,7 +166,7 @@ class File_Gettext_PO extends File_Gettext | ||
| 136 | 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" | 166 | 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
| 137 | ); | 167 | ); |
| 138 | } | 168 | } |
| 139 | - | 169 | + |
| 140 | //done | 170 | //done |
| 141 | @flock($fh, LOCK_UN); | 171 | @flock($fh, LOCK_UN); |
| 142 | @fclose($fh); | 172 | @fclose($fh); |