@@ -109,15 +109,15 @@ |
||
| 109 | 109 | /** |
| 110 | 110 | * Factory method to instantiate a new MessageSource depending on the |
| 111 | 111 | * source type. The allowed source types are 'XLIFF', 'gettext' and |
| 112 | - * 'Database'. The source parameter depends on the source type. |
|
| 113 | - * For 'gettext' and 'XLIFF', 'source' should point to the directory |
|
| 114 | - * where the messages are stored. |
|
| 115 | - * For 'Database', 'source' must be a valid connection id. |
|
| 116 | - * If a deprecated 'SQLite' type is used, 'source' must contain |
|
| 117 | - * a valid DSN. |
|
| 112 | + * 'Database'. The source parameter depends on the source type. |
|
| 113 | + * For 'gettext' and 'XLIFF', 'source' should point to the directory |
|
| 114 | + * where the messages are stored. |
|
| 115 | + * For 'Database', 'source' must be a valid connection id. |
|
| 116 | + * If a deprecated 'SQLite' type is used, 'source' must contain |
|
| 117 | + * a valid DSN. |
|
| 118 | 118 | * |
| 119 | - * Custom message source are possible by supplying the a filename parameter |
|
| 120 | - * in the factory method. |
|
| 119 | + * Custom message source are possible by supplying the a filename parameter |
|
| 120 | + * in the factory method. |
|
| 121 | 121 | * |
| 122 | 122 | * @param string the message source type. |
| 123 | 123 | * @param string the location of the resource or the ConnectionID. |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * Array of translation messages. |
| 82 | 82 | * @var array |
| 83 | 83 | */ |
| 84 | - protected $messages = array(); |
|
| 84 | + protected $messages=array(); |
|
| 85 | 85 | |
| 86 | 86 | /** |
| 87 | 87 | * The source of message translations. |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | protected $cache; |
| 97 | 97 | |
| 98 | - protected $untranslated = array(); |
|
| 98 | + protected $untranslated=array(); |
|
| 99 | 99 | |
| 100 | 100 | /** |
| 101 | 101 | * Private constructor. MessageSource must be initialized using |
@@ -127,23 +127,23 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | static function &factory($type, $source='.', $filename='') |
| 129 | 129 | { |
| 130 | - $types = array('XLIFF','gettext','Database','SQLite'); |
|
| 130 | + $types=array('XLIFF', 'gettext', 'Database', 'SQLite'); |
|
| 131 | 131 | |
| 132 | 132 | if(empty($filename) && !in_array($type, $types)) |
| 133 | 133 | throw new Exception('Invalid type "'.$type.'", valid types are '. |
| 134 | 134 | implode(', ', $types)); |
| 135 | 135 | |
| 136 | - $class = 'MessageSource_'.$type; |
|
| 136 | + $class='MessageSource_'.$type; |
|
| 137 | 137 | |
| 138 | 138 | if(empty($filename)) |
| 139 | - $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
| 139 | + $filename=dirname(__FILE__).'/'.$class.'.php'; |
|
| 140 | 140 | |
| 141 | - if(is_file($filename) == false) |
|
| 141 | + if(is_file($filename)==false) |
|
| 142 | 142 | throw new Exception("File $filename not found"); |
| 143 | 143 | |
| 144 | 144 | include_once $filename; |
| 145 | 145 | |
| 146 | - $obj = new $class($source); |
|
| 146 | + $obj=new $class($source); |
|
| 147 | 147 | |
| 148 | 148 | return $obj; |
| 149 | 149 | } |
@@ -169,36 +169,36 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function load($catalogue='messages') |
| 171 | 171 | { |
| 172 | - $variants = $this->getCatalogueList($catalogue); |
|
| 172 | + $variants=$this->getCatalogueList($catalogue); |
|
| 173 | 173 | |
| 174 | - $this->messages = array(); |
|
| 174 | + $this->messages=array(); |
|
| 175 | 175 | |
| 176 | 176 | foreach($variants as $variant) |
| 177 | 177 | { |
| 178 | - $source = $this->getSource($variant); |
|
| 178 | + $source=$this->getSource($variant); |
|
| 179 | 179 | |
| 180 | - if($this->isValidSource($source) == false) continue; |
|
| 180 | + if($this->isValidSource($source)==false) continue; |
|
| 181 | 181 | |
| 182 | - $loadData = true; |
|
| 182 | + $loadData=true; |
|
| 183 | 183 | |
| 184 | 184 | if($this->cache) |
| 185 | 185 | { |
| 186 | - $data = $this->cache->get($variant, |
|
| 186 | + $data=$this->cache->get($variant, |
|
| 187 | 187 | $this->culture, $this->getLastModified($source)); |
| 188 | 188 | |
| 189 | 189 | if(is_array($data)) |
| 190 | 190 | { |
| 191 | - $this->messages[$variant] = $data; |
|
| 192 | - $loadData = false; |
|
| 191 | + $this->messages[$variant]=$data; |
|
| 192 | + $loadData=false; |
|
| 193 | 193 | } |
| 194 | 194 | unset($data); |
| 195 | 195 | } |
| 196 | 196 | if($loadData) |
| 197 | 197 | { |
| 198 | - $data = &$this->loadData($source); |
|
| 198 | + $data=&$this->loadData($source); |
|
| 199 | 199 | if(is_array($data)) |
| 200 | 200 | { |
| 201 | - $this->messages[$variant] = $data; |
|
| 201 | + $this->messages[$variant]=$data; |
|
| 202 | 202 | if($this->cache) |
| 203 | 203 | $this->cache->save($data, $variant, $this->culture); |
| 204 | 204 | } |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | public function setCache(MessageCache $cache) |
| 236 | 236 | { |
| 237 | - $this->cache = $cache; |
|
| 237 | + $this->cache=$cache; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | public function append($message) |
| 246 | 246 | { |
| 247 | 247 | if(!in_array($message, $this->untranslated)) |
| 248 | - $this->untranslated[] = $message; |
|
| 248 | + $this->untranslated[]=$message; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | public function setCulture($culture) |
| 256 | 256 | { |
| 257 | - $this->culture = $culture; |
|
| 257 | + $this->culture=$culture; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -51,110 +51,110 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | class TGettext_PO extends TGettext |
| 53 | 53 | { |
| 54 | - /** |
|
| 55 | - * Constructor |
|
| 56 | - * |
|
| 57 | - * @access public |
|
| 58 | - * @return object File_Gettext_PO |
|
| 59 | - * @param string path to GNU PO file |
|
| 60 | - */ |
|
| 61 | - function __construct($file = '') |
|
| 62 | - { |
|
| 63 | - $this->file = $file; |
|
| 64 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor |
|
| 56 | + * |
|
| 57 | + * @access public |
|
| 58 | + * @return object File_Gettext_PO |
|
| 59 | + * @param string path to GNU PO file |
|
| 60 | + */ |
|
| 61 | + function __construct($file = '') |
|
| 62 | + { |
|
| 63 | + $this->file = $file; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Load PO file |
|
| 68 | - * |
|
| 69 | - * @access public |
|
| 70 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 71 | - * @param string $file |
|
| 72 | - */ |
|
| 73 | - function load($file = null) |
|
| 74 | - { |
|
| 75 | - if (!isset($file)) { |
|
| 76 | - $file = $this->file; |
|
| 77 | - } |
|
| 66 | + /** |
|
| 67 | + * Load PO file |
|
| 68 | + * |
|
| 69 | + * @access public |
|
| 70 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 71 | + * @param string $file |
|
| 72 | + */ |
|
| 73 | + function load($file = null) |
|
| 74 | + { |
|
| 75 | + if (!isset($file)) { |
|
| 76 | + $file = $this->file; |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - // load file |
|
| 80 | - if (!$contents = @file($file)) { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - $contents = implode('', $contents); |
|
| 79 | + // load file |
|
| 80 | + if (!$contents = @file($file)) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + $contents = implode('', $contents); |
|
| 84 | 84 | |
| 85 | - // match all msgid/msgstr entries |
|
| 86 | - $matched = preg_match_all( |
|
| 87 | - '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . |
|
| 88 | - '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', |
|
| 89 | - $contents, $matches |
|
| 90 | - ); |
|
| 91 | - unset($contents); |
|
| 85 | + // match all msgid/msgstr entries |
|
| 86 | + $matched = preg_match_all( |
|
| 87 | + '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . |
|
| 88 | + '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', |
|
| 89 | + $contents, $matches |
|
| 90 | + ); |
|
| 91 | + unset($contents); |
|
| 92 | 92 | |
| 93 | - if (!$matched) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 93 | + if (!$matched) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // get all msgids and msgtrs |
|
| 98 | - for ($i = 0; $i < $matched; $i++) { |
|
| 99 | - $msgid = preg_replace( |
|
| 100 | - '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); |
|
| 101 | - $msgstr= preg_replace( |
|
| 102 | - '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); |
|
| 103 | - $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
|
| 104 | - } |
|
| 97 | + // get all msgids and msgtrs |
|
| 98 | + for ($i = 0; $i < $matched; $i++) { |
|
| 99 | + $msgid = preg_replace( |
|
| 100 | + '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); |
|
| 101 | + $msgstr= preg_replace( |
|
| 102 | + '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); |
|
| 103 | + $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - // check for meta info |
|
| 107 | - if (isset($this->strings[''])) { |
|
| 108 | - $this->meta = parent::meta2array($this->strings['']); |
|
| 109 | - unset($this->strings['']); |
|
| 110 | - } |
|
| 106 | + // check for meta info |
|
| 107 | + if (isset($this->strings[''])) { |
|
| 108 | + $this->meta = parent::meta2array($this->strings['']); |
|
| 109 | + unset($this->strings['']); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - return true; |
|
| 113 | - } |
|
| 112 | + return true; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Save PO file |
|
| 117 | - * |
|
| 118 | - * @access public |
|
| 119 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 120 | - * @param string $file |
|
| 121 | - */ |
|
| 122 | - function save($file = null) |
|
| 123 | - { |
|
| 124 | - if (!isset($file)) { |
|
| 125 | - $file = $this->file; |
|
| 126 | - } |
|
| 115 | + /** |
|
| 116 | + * Save PO file |
|
| 117 | + * |
|
| 118 | + * @access public |
|
| 119 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 120 | + * @param string $file |
|
| 121 | + */ |
|
| 122 | + function save($file = null) |
|
| 123 | + { |
|
| 124 | + if (!isset($file)) { |
|
| 125 | + $file = $this->file; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - // open PO file |
|
| 129 | - if (!is_resource($fh = @fopen($file, 'w'))) { |
|
| 130 | - return false; |
|
| 131 | - } |
|
| 128 | + // open PO file |
|
| 129 | + if (!is_resource($fh = @fopen($file, 'w'))) { |
|
| 130 | + return false; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // lock PO file exclusively |
|
| 134 | - if (!flock($fh, LOCK_EX)) { |
|
| 135 | - fclose($fh); |
|
| 136 | - return false; |
|
| 137 | - } |
|
| 138 | - // write meta info |
|
| 139 | - if (count($this->meta)) { |
|
| 140 | - $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; |
|
| 141 | - foreach ($this->meta as $k => $v) { |
|
| 142 | - $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; |
|
| 143 | - } |
|
| 144 | - fwrite($fh, $meta . "\n"); |
|
| 145 | - } |
|
| 146 | - // write strings |
|
| 147 | - foreach ($this->strings as $o => $t) { |
|
| 148 | - fwrite($fh, |
|
| 149 | - 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
| 150 | - 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
|
| 151 | - ); |
|
| 152 | - } |
|
| 133 | + // lock PO file exclusively |
|
| 134 | + if (!flock($fh, LOCK_EX)) { |
|
| 135 | + fclose($fh); |
|
| 136 | + return false; |
|
| 137 | + } |
|
| 138 | + // write meta info |
|
| 139 | + if (count($this->meta)) { |
|
| 140 | + $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; |
|
| 141 | + foreach ($this->meta as $k => $v) { |
|
| 142 | + $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; |
|
| 143 | + } |
|
| 144 | + fwrite($fh, $meta . "\n"); |
|
| 145 | + } |
|
| 146 | + // write strings |
|
| 147 | + foreach ($this->strings as $o => $t) { |
|
| 148 | + fwrite($fh, |
|
| 149 | + 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
| 150 | + 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
|
| 151 | + ); |
|
| 152 | + } |
|
| 153 | 153 | |
| 154 | - //done |
|
| 155 | - @flock($fh, LOCK_UN); |
|
| 156 | - @fclose($fh); |
|
| 157 | - chmod($file,PRADO_CHMOD); |
|
| 158 | - return true; |
|
| 159 | - } |
|
| 154 | + //done |
|
| 155 | + @flock($fh, LOCK_UN); |
|
| 156 | + @fclose($fh); |
|
| 157 | + chmod($file,PRADO_CHMOD); |
|
| 158 | + return true; |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * @return object File_Gettext_PO |
| 59 | 59 | * @param string path to GNU PO file |
| 60 | 60 | */ |
| 61 | - function __construct($file = '') |
|
| 61 | + function __construct($file='') |
|
| 62 | 62 | { |
| 63 | - $this->file = $file; |
|
| 63 | + $this->file=$file; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -70,42 +70,42 @@ discard block |
||
| 70 | 70 | * @return mixed Returns true on success or PEAR_Error on failure. |
| 71 | 71 | * @param string $file |
| 72 | 72 | */ |
| 73 | - function load($file = null) |
|
| 73 | + function load($file=null) |
|
| 74 | 74 | { |
| 75 | - if (!isset($file)) { |
|
| 76 | - $file = $this->file; |
|
| 75 | + if(!isset($file)) { |
|
| 76 | + $file=$this->file; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // load file |
| 80 | - if (!$contents = @file($file)) { |
|
| 80 | + if(!$contents=@file($file)) { |
|
| 81 | 81 | return false; |
| 82 | 82 | } |
| 83 | - $contents = implode('', $contents); |
|
| 83 | + $contents=implode('', $contents); |
|
| 84 | 84 | |
| 85 | 85 | // match all msgid/msgstr entries |
| 86 | - $matched = preg_match_all( |
|
| 87 | - '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+' . |
|
| 86 | + $matched=preg_match_all( |
|
| 87 | + '/(msgid\s+("([^"]|\\\\")*?"\s*)+)\s+'. |
|
| 88 | 88 | '(msgstr\s+("([^"]|\\\\")*?"\s*)+)/', |
| 89 | 89 | $contents, $matches |
| 90 | 90 | ); |
| 91 | 91 | unset($contents); |
| 92 | 92 | |
| 93 | - if (!$matched) { |
|
| 93 | + if(!$matched) { |
|
| 94 | 94 | return false; |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // get all msgids and msgtrs |
| 98 | - for ($i = 0; $i < $matched; $i++) { |
|
| 99 | - $msgid = preg_replace( |
|
| 98 | + for($i=0; $i < $matched; $i++) { |
|
| 99 | + $msgid=preg_replace( |
|
| 100 | 100 | '/\s*msgid\s*"(.*)"\s*/s', '\\1', $matches[1][$i]); |
| 101 | - $msgstr= preg_replace( |
|
| 101 | + $msgstr=preg_replace( |
|
| 102 | 102 | '/\s*msgstr\s*"(.*)"\s*/s', '\\1', $matches[4][$i]); |
| 103 | - $this->strings[parent::prepare($msgid)] = parent::prepare($msgstr); |
|
| 103 | + $this->strings[parent::prepare($msgid)]=parent::prepare($msgstr); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // check for meta info |
| 107 | - if (isset($this->strings[''])) { |
|
| 108 | - $this->meta = parent::meta2array($this->strings['']); |
|
| 107 | + if(isset($this->strings[''])) { |
|
| 108 | + $this->meta=parent::meta2array($this->strings['']); |
|
| 109 | 109 | unset($this->strings['']); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -119,42 +119,42 @@ discard block |
||
| 119 | 119 | * @return mixed Returns true on success or PEAR_Error on failure. |
| 120 | 120 | * @param string $file |
| 121 | 121 | */ |
| 122 | - function save($file = null) |
|
| 122 | + function save($file=null) |
|
| 123 | 123 | { |
| 124 | - if (!isset($file)) { |
|
| 125 | - $file = $this->file; |
|
| 124 | + if(!isset($file)) { |
|
| 125 | + $file=$this->file; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // open PO file |
| 129 | - if (!is_resource($fh = @fopen($file, 'w'))) { |
|
| 129 | + if(!is_resource($fh=@fopen($file, 'w'))) { |
|
| 130 | 130 | return false; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | // lock PO file exclusively |
| 134 | - if (!flock($fh, LOCK_EX)) { |
|
| 134 | + if(!flock($fh, LOCK_EX)) { |
|
| 135 | 135 | fclose($fh); |
| 136 | 136 | return false; |
| 137 | 137 | } |
| 138 | 138 | // write meta info |
| 139 | - if (count($this->meta)) { |
|
| 140 | - $meta = 'msgid ""' . "\nmsgstr " . '""' . "\n"; |
|
| 141 | - foreach ($this->meta as $k => $v) { |
|
| 142 | - $meta .= '"' . $k . ': ' . $v . '\n"' . "\n"; |
|
| 139 | + if(count($this->meta)) { |
|
| 140 | + $meta='msgid ""'."\nmsgstr ".'""'."\n"; |
|
| 141 | + foreach($this->meta as $k => $v) { |
|
| 142 | + $meta.='"'.$k.': '.$v.'\n"'."\n"; |
|
| 143 | 143 | } |
| 144 | - fwrite($fh, $meta . "\n"); |
|
| 144 | + fwrite($fh, $meta."\n"); |
|
| 145 | 145 | } |
| 146 | 146 | // write strings |
| 147 | - foreach ($this->strings as $o => $t) { |
|
| 147 | + foreach($this->strings as $o => $t) { |
|
| 148 | 148 | fwrite($fh, |
| 149 | - 'msgid "' . parent::prepare($o, true) . '"' . "\n" . |
|
| 150 | - 'msgstr "' . parent::prepare($t, true) . '"' . "\n\n" |
|
| 149 | + 'msgid "'.parent::prepare($o, true).'"'."\n". |
|
| 150 | + 'msgstr "'.parent::prepare($t, true).'"'."\n\n" |
|
| 151 | 151 | ); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | //done |
| 155 | 155 | @flock($fh, LOCK_UN); |
| 156 | 156 | @fclose($fh); |
| 157 | - chmod($file,PRADO_CHMOD); |
|
| 157 | + chmod($file, PRADO_CHMOD); |
|
| 158 | 158 | return true; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -1,20 +1,20 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * TGettext_MO class file. |
|
| 4 | - * |
|
| 5 | - * This program is free software; you can redistribute it and/or modify |
|
| 6 | - * it under the terms of the BSD License. |
|
| 7 | - * |
|
| 8 | - * Copyright(c) 2004 by Qiang Xue. All rights reserved. |
|
| 9 | - * |
|
| 10 | - * To contact the author write to {@link mailto:[email protected] Qiang Xue} |
|
| 11 | - * The latest version of PRADO can be obtained from: |
|
| 12 | - * {@link http://prado.sourceforge.net/} |
|
| 13 | - * |
|
| 14 | - * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
| 15 | - * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $ |
|
| 16 | - * @package System.I18N.core |
|
| 17 | - */ |
|
| 3 | + * TGettext_MO class file. |
|
| 4 | + * |
|
| 5 | + * This program is free software; you can redistribute it and/or modify |
|
| 6 | + * it under the terms of the BSD License. |
|
| 7 | + * |
|
| 8 | + * Copyright(c) 2004 by Qiang Xue. All rights reserved. |
|
| 9 | + * |
|
| 10 | + * To contact the author write to {@link mailto:[email protected] Qiang Xue} |
|
| 11 | + * The latest version of PRADO can be obtained from: |
|
| 12 | + * {@link http://prado.sourceforge.net/} |
|
| 13 | + * |
|
| 14 | + * @author Wei Zhuo <weizhuo[at]gmail[dot]com> |
|
| 15 | + * @version $Revision: 1.3 $ $Date: 2005/08/27 03:21:12 $ |
|
| 16 | + * @package System.I18N.core |
|
| 17 | + */ |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | 20 | // +----------------------------------------------------------------------+ |
@@ -52,304 +52,304 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | class TGettext_MO extends TGettext |
| 54 | 54 | { |
| 55 | - /** |
|
| 56 | - * file handle |
|
| 57 | - * |
|
| 58 | - * @access private |
|
| 59 | - * @var resource |
|
| 60 | - */ |
|
| 61 | - protected $_handle = null; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * big endianess |
|
| 65 | - * |
|
| 66 | - * Whether to write with big endian byte order. |
|
| 67 | - * |
|
| 68 | - * @access public |
|
| 69 | - * @var bool |
|
| 70 | - */ |
|
| 71 | - protected $writeBigEndian = false; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Constructor |
|
| 75 | - * |
|
| 76 | - * @access public |
|
| 77 | - * @return object File_Gettext_MO |
|
| 78 | - * @param string $file path to GNU MO file |
|
| 79 | - */ |
|
| 80 | - function __construct($file = '') |
|
| 81 | - { |
|
| 82 | - $this->file = $file; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * _read |
|
| 87 | - * |
|
| 88 | - * @access private |
|
| 89 | - * @return mixed |
|
| 90 | - * @param int $bytes |
|
| 91 | - */ |
|
| 92 | - function _read($bytes = 1) |
|
| 93 | - { |
|
| 94 | - if (0 < $bytes = abs($bytes)) { |
|
| 95 | - return fread($this->_handle, $bytes); |
|
| 96 | - } |
|
| 97 | - return null; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * _readInt |
|
| 102 | - * |
|
| 103 | - * @access private |
|
| 104 | - * @return int |
|
| 105 | - * @param bool $bigendian |
|
| 106 | - */ |
|
| 107 | - function _readInt($bigendian = false) |
|
| 108 | - { |
|
| 55 | + /** |
|
| 56 | + * file handle |
|
| 57 | + * |
|
| 58 | + * @access private |
|
| 59 | + * @var resource |
|
| 60 | + */ |
|
| 61 | + protected $_handle = null; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * big endianess |
|
| 65 | + * |
|
| 66 | + * Whether to write with big endian byte order. |
|
| 67 | + * |
|
| 68 | + * @access public |
|
| 69 | + * @var bool |
|
| 70 | + */ |
|
| 71 | + protected $writeBigEndian = false; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Constructor |
|
| 75 | + * |
|
| 76 | + * @access public |
|
| 77 | + * @return object File_Gettext_MO |
|
| 78 | + * @param string $file path to GNU MO file |
|
| 79 | + */ |
|
| 80 | + function __construct($file = '') |
|
| 81 | + { |
|
| 82 | + $this->file = $file; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * _read |
|
| 87 | + * |
|
| 88 | + * @access private |
|
| 89 | + * @return mixed |
|
| 90 | + * @param int $bytes |
|
| 91 | + */ |
|
| 92 | + function _read($bytes = 1) |
|
| 93 | + { |
|
| 94 | + if (0 < $bytes = abs($bytes)) { |
|
| 95 | + return fread($this->_handle, $bytes); |
|
| 96 | + } |
|
| 97 | + return null; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * _readInt |
|
| 102 | + * |
|
| 103 | + * @access private |
|
| 104 | + * @return int |
|
| 105 | + * @param bool $bigendian |
|
| 106 | + */ |
|
| 107 | + function _readInt($bigendian = false) |
|
| 108 | + { |
|
| 109 | 109 | //unpack returns a reference???? |
| 110 | 110 | $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4)); |
| 111 | - return array_shift($unpacked); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * _writeInt |
|
| 116 | - * |
|
| 117 | - * @access private |
|
| 118 | - * @return int |
|
| 119 | - * @param int $int |
|
| 120 | - */ |
|
| 121 | - function _writeInt($int) |
|
| 122 | - { |
|
| 123 | - return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * _write |
|
| 128 | - * |
|
| 129 | - * @access private |
|
| 130 | - * @return int |
|
| 131 | - * @param string $data |
|
| 132 | - */ |
|
| 133 | - function _write($data) |
|
| 134 | - { |
|
| 135 | - return fwrite($this->_handle, $data); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * _writeStr |
|
| 140 | - * |
|
| 141 | - * @access private |
|
| 142 | - * @return int |
|
| 143 | - * @param string $string |
|
| 144 | - */ |
|
| 145 | - function _writeStr($string) |
|
| 146 | - { |
|
| 147 | - return $this->_write($string . "\0"); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * _readStr |
|
| 152 | - * |
|
| 153 | - * @access private |
|
| 154 | - * @return string |
|
| 155 | - * @param array $params associative array with offset and length |
|
| 156 | - * of the string |
|
| 157 | - */ |
|
| 158 | - function _readStr($params) |
|
| 159 | - { |
|
| 160 | - fseek($this->_handle, $params['offset']); |
|
| 161 | - return $this->_read($params['length']); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Load MO file |
|
| 166 | - * |
|
| 167 | - * @access public |
|
| 168 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 169 | - * @param string $file |
|
| 170 | - */ |
|
| 171 | - function load($file = null) |
|
| 172 | - { |
|
| 173 | - if (!isset($file)) { |
|
| 174 | - $file = $this->file; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - // open MO file |
|
| 178 | - if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
| 179 | - return false; |
|
| 180 | - } |
|
| 181 | - // lock MO file shared |
|
| 182 | - if (!@flock($this->_handle, LOCK_SH)) { |
|
| 183 | - @fclose($this->_handle); |
|
| 184 | - return false; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - // read (part of) magic number from MO file header and define endianess |
|
| 111 | + return array_shift($unpacked); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * _writeInt |
|
| 116 | + * |
|
| 117 | + * @access private |
|
| 118 | + * @return int |
|
| 119 | + * @param int $int |
|
| 120 | + */ |
|
| 121 | + function _writeInt($int) |
|
| 122 | + { |
|
| 123 | + return $this->_write(pack($this->writeBigEndian ? 'N' : 'V', (int) $int)); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * _write |
|
| 128 | + * |
|
| 129 | + * @access private |
|
| 130 | + * @return int |
|
| 131 | + * @param string $data |
|
| 132 | + */ |
|
| 133 | + function _write($data) |
|
| 134 | + { |
|
| 135 | + return fwrite($this->_handle, $data); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * _writeStr |
|
| 140 | + * |
|
| 141 | + * @access private |
|
| 142 | + * @return int |
|
| 143 | + * @param string $string |
|
| 144 | + */ |
|
| 145 | + function _writeStr($string) |
|
| 146 | + { |
|
| 147 | + return $this->_write($string . "\0"); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * _readStr |
|
| 152 | + * |
|
| 153 | + * @access private |
|
| 154 | + * @return string |
|
| 155 | + * @param array $params associative array with offset and length |
|
| 156 | + * of the string |
|
| 157 | + */ |
|
| 158 | + function _readStr($params) |
|
| 159 | + { |
|
| 160 | + fseek($this->_handle, $params['offset']); |
|
| 161 | + return $this->_read($params['length']); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Load MO file |
|
| 166 | + * |
|
| 167 | + * @access public |
|
| 168 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 169 | + * @param string $file |
|
| 170 | + */ |
|
| 171 | + function load($file = null) |
|
| 172 | + { |
|
| 173 | + if (!isset($file)) { |
|
| 174 | + $file = $this->file; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + // open MO file |
|
| 178 | + if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
| 179 | + return false; |
|
| 180 | + } |
|
| 181 | + // lock MO file shared |
|
| 182 | + if (!@flock($this->_handle, LOCK_SH)) { |
|
| 183 | + @fclose($this->_handle); |
|
| 184 | + return false; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + // read (part of) magic number from MO file header and define endianess |
|
| 188 | 188 | |
| 189 | 189 | //unpack returns a reference???? |
| 190 | 190 | $unpacked = unpack('c', $this->_read(4)); |
| 191 | - switch ($magic = array_shift($unpacked)) |
|
| 192 | - { |
|
| 193 | - case -34: |
|
| 194 | - $be = false; |
|
| 195 | - break; |
|
| 196 | - |
|
| 197 | - case -107: |
|
| 198 | - $be = true; |
|
| 199 | - break; |
|
| 200 | - |
|
| 201 | - default: |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // check file format revision - we currently only support 0 |
|
| 206 | - if (0 !== ($_rev = $this->_readInt($be))) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // count of strings in this file |
|
| 211 | - $count = $this->_readInt($be); |
|
| 212 | - |
|
| 213 | - // offset of hashing table of the msgids |
|
| 214 | - $offset_original = $this->_readInt($be); |
|
| 215 | - // offset of hashing table of the msgstrs |
|
| 216 | - $offset_translat = $this->_readInt($be); |
|
| 217 | - |
|
| 218 | - // move to msgid hash table |
|
| 219 | - fseek($this->_handle, $offset_original); |
|
| 220 | - // read lengths and offsets of msgids |
|
| 221 | - $original = array(); |
|
| 222 | - for ($i = 0; $i < $count; $i++) { |
|
| 223 | - $original[$i] = array( |
|
| 224 | - 'length' => $this->_readInt($be), |
|
| 225 | - 'offset' => $this->_readInt($be) |
|
| 226 | - ); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // move to msgstr hash table |
|
| 230 | - fseek($this->_handle, $offset_translat); |
|
| 231 | - // read lengths and offsets of msgstrs |
|
| 232 | - $translat = array(); |
|
| 233 | - for ($i = 0; $i < $count; $i++) { |
|
| 234 | - $translat[$i] = array( |
|
| 235 | - 'length' => $this->_readInt($be), |
|
| 236 | - 'offset' => $this->_readInt($be) |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // read all |
|
| 241 | - for ($i = 0; $i < $count; $i++) { |
|
| 242 | - $this->strings[$this->_readStr($original[$i])] = |
|
| 243 | - $this->_readStr($translat[$i]); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // done |
|
| 247 | - @flock($this->_handle, LOCK_UN); |
|
| 248 | - @fclose($this->_handle); |
|
| 249 | - $this->_handle = null; |
|
| 250 | - |
|
| 251 | - // check for meta info |
|
| 252 | - if (isset($this->strings[''])) { |
|
| 253 | - $this->meta = parent::meta2array($this->strings['']); |
|
| 254 | - unset($this->strings['']); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return true; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * Save MO file |
|
| 262 | - * |
|
| 263 | - * @access public |
|
| 264 | - * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 265 | - * @param string $file |
|
| 266 | - */ |
|
| 267 | - function save($file = null) |
|
| 268 | - { |
|
| 269 | - if (!isset($file)) { |
|
| 270 | - $file = $this->file; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // open MO file |
|
| 274 | - if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
| 275 | - return false; |
|
| 276 | - } |
|
| 277 | - // lock MO file exclusively |
|
| 278 | - if (!@flock($this->_handle, LOCK_EX)) { |
|
| 279 | - @fclose($this->_handle); |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // write magic number |
|
| 284 | - if ($this->writeBigEndian) { |
|
| 285 | - $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
|
| 286 | - } else { |
|
| 287 | - $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - // write file format revision |
|
| 291 | - $this->_writeInt(0); |
|
| 292 | - |
|
| 293 | - $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
| 294 | - // write count of strings |
|
| 295 | - $this->_writeInt($count); |
|
| 296 | - |
|
| 297 | - $offset = 28; |
|
| 298 | - // write offset of orig. strings hash table |
|
| 299 | - $this->_writeInt($offset); |
|
| 300 | - |
|
| 301 | - $offset += ($count * 8); |
|
| 302 | - // write offset transl. strings hash table |
|
| 303 | - $this->_writeInt($offset); |
|
| 304 | - |
|
| 305 | - // write size of hash table (we currently ommit the hash table) |
|
| 306 | - $this->_writeInt(0); |
|
| 307 | - |
|
| 308 | - $offset += ($count * 8); |
|
| 309 | - // write offset of hash table |
|
| 310 | - $this->_writeInt($offset); |
|
| 311 | - |
|
| 312 | - // unshift meta info |
|
| 313 | - if ($this->meta) { |
|
| 314 | - $meta = ''; |
|
| 315 | - foreach ($this->meta as $key => $val) { |
|
| 316 | - $meta .= $key . ': ' . $val . "\n"; |
|
| 317 | - } |
|
| 318 | - $strings = array('' => $meta) + $this->strings; |
|
| 319 | - } else { |
|
| 320 | - $strings = $this->strings; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // write offsets for original strings |
|
| 324 | - foreach (array_keys($strings) as $o) { |
|
| 325 | - $len = strlen($o); |
|
| 326 | - $this->_writeInt($len); |
|
| 327 | - $this->_writeInt($offset); |
|
| 328 | - $offset += $len + 1; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // write offsets for translated strings |
|
| 332 | - foreach ($strings as $t) { |
|
| 333 | - $len = strlen($t); |
|
| 334 | - $this->_writeInt($len); |
|
| 335 | - $this->_writeInt($offset); |
|
| 336 | - $offset += $len + 1; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - // write original strings |
|
| 340 | - foreach (array_keys($strings) as $o) { |
|
| 341 | - $this->_writeStr($o); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - // write translated strings |
|
| 345 | - foreach ($strings as $t) { |
|
| 346 | - $this->_writeStr($t); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - // done |
|
| 350 | - @flock($this->_handle, LOCK_UN); |
|
| 351 | - @fclose($this->_handle); |
|
| 352 | - chmod($file,PRADO_CHMOD); |
|
| 353 | - return true; |
|
| 354 | - } |
|
| 191 | + switch ($magic = array_shift($unpacked)) |
|
| 192 | + { |
|
| 193 | + case -34: |
|
| 194 | + $be = false; |
|
| 195 | + break; |
|
| 196 | + |
|
| 197 | + case -107: |
|
| 198 | + $be = true; |
|
| 199 | + break; |
|
| 200 | + |
|
| 201 | + default: |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // check file format revision - we currently only support 0 |
|
| 206 | + if (0 !== ($_rev = $this->_readInt($be))) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // count of strings in this file |
|
| 211 | + $count = $this->_readInt($be); |
|
| 212 | + |
|
| 213 | + // offset of hashing table of the msgids |
|
| 214 | + $offset_original = $this->_readInt($be); |
|
| 215 | + // offset of hashing table of the msgstrs |
|
| 216 | + $offset_translat = $this->_readInt($be); |
|
| 217 | + |
|
| 218 | + // move to msgid hash table |
|
| 219 | + fseek($this->_handle, $offset_original); |
|
| 220 | + // read lengths and offsets of msgids |
|
| 221 | + $original = array(); |
|
| 222 | + for ($i = 0; $i < $count; $i++) { |
|
| 223 | + $original[$i] = array( |
|
| 224 | + 'length' => $this->_readInt($be), |
|
| 225 | + 'offset' => $this->_readInt($be) |
|
| 226 | + ); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // move to msgstr hash table |
|
| 230 | + fseek($this->_handle, $offset_translat); |
|
| 231 | + // read lengths and offsets of msgstrs |
|
| 232 | + $translat = array(); |
|
| 233 | + for ($i = 0; $i < $count; $i++) { |
|
| 234 | + $translat[$i] = array( |
|
| 235 | + 'length' => $this->_readInt($be), |
|
| 236 | + 'offset' => $this->_readInt($be) |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // read all |
|
| 241 | + for ($i = 0; $i < $count; $i++) { |
|
| 242 | + $this->strings[$this->_readStr($original[$i])] = |
|
| 243 | + $this->_readStr($translat[$i]); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // done |
|
| 247 | + @flock($this->_handle, LOCK_UN); |
|
| 248 | + @fclose($this->_handle); |
|
| 249 | + $this->_handle = null; |
|
| 250 | + |
|
| 251 | + // check for meta info |
|
| 252 | + if (isset($this->strings[''])) { |
|
| 253 | + $this->meta = parent::meta2array($this->strings['']); |
|
| 254 | + unset($this->strings['']); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return true; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * Save MO file |
|
| 262 | + * |
|
| 263 | + * @access public |
|
| 264 | + * @return mixed Returns true on success or PEAR_Error on failure. |
|
| 265 | + * @param string $file |
|
| 266 | + */ |
|
| 267 | + function save($file = null) |
|
| 268 | + { |
|
| 269 | + if (!isset($file)) { |
|
| 270 | + $file = $this->file; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // open MO file |
|
| 274 | + if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
| 275 | + return false; |
|
| 276 | + } |
|
| 277 | + // lock MO file exclusively |
|
| 278 | + if (!@flock($this->_handle, LOCK_EX)) { |
|
| 279 | + @fclose($this->_handle); |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // write magic number |
|
| 284 | + if ($this->writeBigEndian) { |
|
| 285 | + $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
|
| 286 | + } else { |
|
| 287 | + $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + // write file format revision |
|
| 291 | + $this->_writeInt(0); |
|
| 292 | + |
|
| 293 | + $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
| 294 | + // write count of strings |
|
| 295 | + $this->_writeInt($count); |
|
| 296 | + |
|
| 297 | + $offset = 28; |
|
| 298 | + // write offset of orig. strings hash table |
|
| 299 | + $this->_writeInt($offset); |
|
| 300 | + |
|
| 301 | + $offset += ($count * 8); |
|
| 302 | + // write offset transl. strings hash table |
|
| 303 | + $this->_writeInt($offset); |
|
| 304 | + |
|
| 305 | + // write size of hash table (we currently ommit the hash table) |
|
| 306 | + $this->_writeInt(0); |
|
| 307 | + |
|
| 308 | + $offset += ($count * 8); |
|
| 309 | + // write offset of hash table |
|
| 310 | + $this->_writeInt($offset); |
|
| 311 | + |
|
| 312 | + // unshift meta info |
|
| 313 | + if ($this->meta) { |
|
| 314 | + $meta = ''; |
|
| 315 | + foreach ($this->meta as $key => $val) { |
|
| 316 | + $meta .= $key . ': ' . $val . "\n"; |
|
| 317 | + } |
|
| 318 | + $strings = array('' => $meta) + $this->strings; |
|
| 319 | + } else { |
|
| 320 | + $strings = $this->strings; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // write offsets for original strings |
|
| 324 | + foreach (array_keys($strings) as $o) { |
|
| 325 | + $len = strlen($o); |
|
| 326 | + $this->_writeInt($len); |
|
| 327 | + $this->_writeInt($offset); |
|
| 328 | + $offset += $len + 1; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // write offsets for translated strings |
|
| 332 | + foreach ($strings as $t) { |
|
| 333 | + $len = strlen($t); |
|
| 334 | + $this->_writeInt($len); |
|
| 335 | + $this->_writeInt($offset); |
|
| 336 | + $offset += $len + 1; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + // write original strings |
|
| 340 | + foreach (array_keys($strings) as $o) { |
|
| 341 | + $this->_writeStr($o); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + // write translated strings |
|
| 345 | + foreach ($strings as $t) { |
|
| 346 | + $this->_writeStr($t); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + // done |
|
| 350 | + @flock($this->_handle, LOCK_UN); |
|
| 351 | + @fclose($this->_handle); |
|
| 352 | + chmod($file,PRADO_CHMOD); |
|
| 353 | + return true; |
|
| 354 | + } |
|
| 355 | 355 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @access private |
| 59 | 59 | * @var resource |
| 60 | 60 | */ |
| 61 | - protected $_handle = null; |
|
| 61 | + protected $_handle=null; |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * big endianess |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @access public |
| 69 | 69 | * @var bool |
| 70 | 70 | */ |
| 71 | - protected $writeBigEndian = false; |
|
| 71 | + protected $writeBigEndian=false; |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Constructor |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @return object File_Gettext_MO |
| 78 | 78 | * @param string $file path to GNU MO file |
| 79 | 79 | */ |
| 80 | - function __construct($file = '') |
|
| 80 | + function __construct($file='') |
|
| 81 | 81 | { |
| 82 | - $this->file = $file; |
|
| 82 | + $this->file=$file; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * @return mixed |
| 90 | 90 | * @param int $bytes |
| 91 | 91 | */ |
| 92 | - function _read($bytes = 1) |
|
| 92 | + function _read($bytes=1) |
|
| 93 | 93 | { |
| 94 | - if (0 < $bytes = abs($bytes)) { |
|
| 94 | + if(0 < $bytes=abs($bytes)) { |
|
| 95 | 95 | return fread($this->_handle, $bytes); |
| 96 | 96 | } |
| 97 | 97 | return null; |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * @return int |
| 105 | 105 | * @param bool $bigendian |
| 106 | 106 | */ |
| 107 | - function _readInt($bigendian = false) |
|
| 107 | + function _readInt($bigendian=false) |
|
| 108 | 108 | { |
| 109 | 109 | //unpack returns a reference???? |
| 110 | - $unpacked = unpack($bigendian ? 'N' : 'V', $this->_read(4)); |
|
| 110 | + $unpacked=unpack($bigendian ? 'N' : 'V', $this->_read(4)); |
|
| 111 | 111 | return array_shift($unpacked); |
| 112 | 112 | } |
| 113 | 113 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | */ |
| 145 | 145 | function _writeStr($string) |
| 146 | 146 | { |
| 147 | - return $this->_write($string . "\0"); |
|
| 147 | + return $this->_write($string."\0"); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -168,18 +168,18 @@ discard block |
||
| 168 | 168 | * @return mixed Returns true on success or PEAR_Error on failure. |
| 169 | 169 | * @param string $file |
| 170 | 170 | */ |
| 171 | - function load($file = null) |
|
| 171 | + function load($file=null) |
|
| 172 | 172 | { |
| 173 | - if (!isset($file)) { |
|
| 174 | - $file = $this->file; |
|
| 173 | + if(!isset($file)) { |
|
| 174 | + $file=$this->file; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | // open MO file |
| 178 | - if (!is_resource($this->_handle = @fopen($file, 'rb'))) { |
|
| 178 | + if(!is_resource($this->_handle=@fopen($file, 'rb'))) { |
|
| 179 | 179 | return false; |
| 180 | 180 | } |
| 181 | 181 | // lock MO file shared |
| 182 | - if (!@flock($this->_handle, LOCK_SH)) { |
|
| 182 | + if(!@flock($this->_handle, LOCK_SH)) { |
|
| 183 | 183 | @fclose($this->_handle); |
| 184 | 184 | return false; |
| 185 | 185 | } |
@@ -187,15 +187,15 @@ discard block |
||
| 187 | 187 | // read (part of) magic number from MO file header and define endianess |
| 188 | 188 | |
| 189 | 189 | //unpack returns a reference???? |
| 190 | - $unpacked = unpack('c', $this->_read(4)); |
|
| 191 | - switch ($magic = array_shift($unpacked)) |
|
| 190 | + $unpacked=unpack('c', $this->_read(4)); |
|
| 191 | + switch($magic=array_shift($unpacked)) |
|
| 192 | 192 | { |
| 193 | 193 | case -34: |
| 194 | - $be = false; |
|
| 194 | + $be=false; |
|
| 195 | 195 | break; |
| 196 | 196 | |
| 197 | 197 | case -107: |
| 198 | - $be = true; |
|
| 198 | + $be=true; |
|
| 199 | 199 | break; |
| 200 | 200 | |
| 201 | 201 | default: |
@@ -203,24 +203,24 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // check file format revision - we currently only support 0 |
| 206 | - if (0 !== ($_rev = $this->_readInt($be))) { |
|
| 206 | + if(0!==($_rev=$this->_readInt($be))) { |
|
| 207 | 207 | return false; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // count of strings in this file |
| 211 | - $count = $this->_readInt($be); |
|
| 211 | + $count=$this->_readInt($be); |
|
| 212 | 212 | |
| 213 | 213 | // offset of hashing table of the msgids |
| 214 | - $offset_original = $this->_readInt($be); |
|
| 214 | + $offset_original=$this->_readInt($be); |
|
| 215 | 215 | // offset of hashing table of the msgstrs |
| 216 | - $offset_translat = $this->_readInt($be); |
|
| 216 | + $offset_translat=$this->_readInt($be); |
|
| 217 | 217 | |
| 218 | 218 | // move to msgid hash table |
| 219 | 219 | fseek($this->_handle, $offset_original); |
| 220 | 220 | // read lengths and offsets of msgids |
| 221 | - $original = array(); |
|
| 222 | - for ($i = 0; $i < $count; $i++) { |
|
| 223 | - $original[$i] = array( |
|
| 221 | + $original=array(); |
|
| 222 | + for($i=0; $i < $count; $i++) { |
|
| 223 | + $original[$i]=array( |
|
| 224 | 224 | 'length' => $this->_readInt($be), |
| 225 | 225 | 'offset' => $this->_readInt($be) |
| 226 | 226 | ); |
@@ -229,28 +229,28 @@ discard block |
||
| 229 | 229 | // move to msgstr hash table |
| 230 | 230 | fseek($this->_handle, $offset_translat); |
| 231 | 231 | // read lengths and offsets of msgstrs |
| 232 | - $translat = array(); |
|
| 233 | - for ($i = 0; $i < $count; $i++) { |
|
| 234 | - $translat[$i] = array( |
|
| 232 | + $translat=array(); |
|
| 233 | + for($i=0; $i < $count; $i++) { |
|
| 234 | + $translat[$i]=array( |
|
| 235 | 235 | 'length' => $this->_readInt($be), |
| 236 | 236 | 'offset' => $this->_readInt($be) |
| 237 | 237 | ); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // read all |
| 241 | - for ($i = 0; $i < $count; $i++) { |
|
| 242 | - $this->strings[$this->_readStr($original[$i])] = |
|
| 241 | + for($i=0; $i < $count; $i++) { |
|
| 242 | + $this->strings[$this->_readStr($original[$i])]= |
|
| 243 | 243 | $this->_readStr($translat[$i]); |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | // done |
| 247 | 247 | @flock($this->_handle, LOCK_UN); |
| 248 | 248 | @fclose($this->_handle); |
| 249 | - $this->_handle = null; |
|
| 249 | + $this->_handle=null; |
|
| 250 | 250 | |
| 251 | 251 | // check for meta info |
| 252 | - if (isset($this->strings[''])) { |
|
| 253 | - $this->meta = parent::meta2array($this->strings['']); |
|
| 252 | + if(isset($this->strings[''])) { |
|
| 253 | + $this->meta=parent::meta2array($this->strings['']); |
|
| 254 | 254 | unset($this->strings['']); |
| 255 | 255 | } |
| 256 | 256 | |
@@ -264,24 +264,24 @@ discard block |
||
| 264 | 264 | * @return mixed Returns true on success or PEAR_Error on failure. |
| 265 | 265 | * @param string $file |
| 266 | 266 | */ |
| 267 | - function save($file = null) |
|
| 267 | + function save($file=null) |
|
| 268 | 268 | { |
| 269 | - if (!isset($file)) { |
|
| 270 | - $file = $this->file; |
|
| 269 | + if(!isset($file)) { |
|
| 270 | + $file=$this->file; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // open MO file |
| 274 | - if (!is_resource($this->_handle = @fopen($file, 'wb'))) { |
|
| 274 | + if(!is_resource($this->_handle=@fopen($file, 'wb'))) { |
|
| 275 | 275 | return false; |
| 276 | 276 | } |
| 277 | 277 | // lock MO file exclusively |
| 278 | - if (!@flock($this->_handle, LOCK_EX)) { |
|
| 278 | + if(!@flock($this->_handle, LOCK_EX)) { |
|
| 279 | 279 | @fclose($this->_handle); |
| 280 | 280 | return false; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | // write magic number |
| 284 | - if ($this->writeBigEndian) { |
|
| 284 | + if($this->writeBigEndian) { |
|
| 285 | 285 | $this->_write(pack('c*', 0x95, 0x04, 0x12, 0xde)); |
| 286 | 286 | } else { |
| 287 | 287 | $this->_write(pack('c*', 0xde, 0x12, 0x04, 0x95)); |
@@ -290,66 +290,66 @@ discard block |
||
| 290 | 290 | // write file format revision |
| 291 | 291 | $this->_writeInt(0); |
| 292 | 292 | |
| 293 | - $count = count($this->strings) + ($meta = (count($this->meta) ? 1 : 0)); |
|
| 293 | + $count=count($this->strings) + ($meta=(count($this->meta) ? 1 : 0)); |
|
| 294 | 294 | // write count of strings |
| 295 | 295 | $this->_writeInt($count); |
| 296 | 296 | |
| 297 | - $offset = 28; |
|
| 297 | + $offset=28; |
|
| 298 | 298 | // write offset of orig. strings hash table |
| 299 | 299 | $this->_writeInt($offset); |
| 300 | 300 | |
| 301 | - $offset += ($count * 8); |
|
| 301 | + $offset+=($count * 8); |
|
| 302 | 302 | // write offset transl. strings hash table |
| 303 | 303 | $this->_writeInt($offset); |
| 304 | 304 | |
| 305 | 305 | // write size of hash table (we currently ommit the hash table) |
| 306 | 306 | $this->_writeInt(0); |
| 307 | 307 | |
| 308 | - $offset += ($count * 8); |
|
| 308 | + $offset+=($count * 8); |
|
| 309 | 309 | // write offset of hash table |
| 310 | 310 | $this->_writeInt($offset); |
| 311 | 311 | |
| 312 | 312 | // unshift meta info |
| 313 | - if ($this->meta) { |
|
| 314 | - $meta = ''; |
|
| 315 | - foreach ($this->meta as $key => $val) { |
|
| 316 | - $meta .= $key . ': ' . $val . "\n"; |
|
| 313 | + if($this->meta) { |
|
| 314 | + $meta=''; |
|
| 315 | + foreach($this->meta as $key => $val) { |
|
| 316 | + $meta.=$key.': '.$val."\n"; |
|
| 317 | 317 | } |
| 318 | - $strings = array('' => $meta) + $this->strings; |
|
| 318 | + $strings=array('' => $meta) + $this->strings; |
|
| 319 | 319 | } else { |
| 320 | - $strings = $this->strings; |
|
| 320 | + $strings=$this->strings; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | // write offsets for original strings |
| 324 | - foreach (array_keys($strings) as $o) { |
|
| 325 | - $len = strlen($o); |
|
| 324 | + foreach(array_keys($strings) as $o) { |
|
| 325 | + $len=strlen($o); |
|
| 326 | 326 | $this->_writeInt($len); |
| 327 | 327 | $this->_writeInt($offset); |
| 328 | - $offset += $len + 1; |
|
| 328 | + $offset+=$len + 1; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // write offsets for translated strings |
| 332 | - foreach ($strings as $t) { |
|
| 333 | - $len = strlen($t); |
|
| 332 | + foreach($strings as $t) { |
|
| 333 | + $len=strlen($t); |
|
| 334 | 334 | $this->_writeInt($len); |
| 335 | 335 | $this->_writeInt($offset); |
| 336 | - $offset += $len + 1; |
|
| 336 | + $offset+=$len + 1; |
|
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | // write original strings |
| 340 | - foreach (array_keys($strings) as $o) { |
|
| 340 | + foreach(array_keys($strings) as $o) { |
|
| 341 | 341 | $this->_writeStr($o); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | // write translated strings |
| 345 | - foreach ($strings as $t) { |
|
| 345 | + foreach($strings as $t) { |
|
| 346 | 346 | $this->_writeStr($t); |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | // done |
| 350 | 350 | @flock($this->_handle, LOCK_UN); |
| 351 | 351 | @fclose($this->_handle); |
| 352 | - chmod($file,PRADO_CHMOD); |
|
| 352 | + chmod($file, PRADO_CHMOD); |
|
| 353 | 353 | return true; |
| 354 | 354 | } |
| 355 | 355 | } |