@@ -246,6 +246,9 @@ discard block |
||
| 246 | 246 | return false; |
| 247 | 247 | } |
| 248 | 248 | |
| 249 | + /** |
|
| 250 | + * @param string $filename |
|
| 251 | + */ |
|
| 249 | 252 | protected function internalSaveFile($php, $filename) |
| 250 | 253 | { |
| 251 | 254 | $php['info']['date'] = @date('Y-m-d\TH:i:s\Z'); |
@@ -377,6 +380,9 @@ discard block |
||
| 377 | 380 | return false; |
| 378 | 381 | } |
| 379 | 382 | |
| 383 | + /** |
|
| 384 | + * @param string $catalogue |
|
| 385 | + */ |
|
| 380 | 386 | protected function createMessageTemplate($catalogue) |
| 381 | 387 | { |
| 382 | 388 | if($catalogue === null) { |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | * Message data filename extension. |
| 41 | 41 | * @var string |
| 42 | 42 | */ |
| 43 | - protected $dataExt = '.php'; |
|
| 43 | + protected $dataExt='.php'; |
|
| 44 | 44 | |
| 45 | 45 | /** |
| 46 | 46 | * Separator between culture name and source. |
| 47 | 47 | * @var string |
| 48 | 48 | */ |
| 49 | - protected $dataSeparator = '.'; |
|
| 49 | + protected $dataSeparator='.'; |
|
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * Constructor. |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function __construct($source) |
| 57 | 57 | { |
| 58 | - $this->source = (string)$source; |
|
| 58 | + $this->source=(string) $source; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -66,20 +66,20 @@ discard block |
||
| 66 | 66 | protected function &loadData($filename) |
| 67 | 67 | { |
| 68 | 68 | //load it. |
| 69 | - if(false === ($php = include($filename))) { |
|
| 69 | + if(false===($php=include($filename))) { |
|
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - $translationUnit = $php['trans-unit']; |
|
| 73 | + $translationUnit=$php['trans-unit']; |
|
| 74 | 74 | |
| 75 | - $translations = array(); |
|
| 75 | + $translations=array(); |
|
| 76 | 76 | |
| 77 | 77 | foreach($translationUnit as $k => $unit) |
| 78 | 78 | { |
| 79 | - $source = (string)$unit['source']; |
|
| 80 | - $translations[$source][] = (string)$unit['target']; |
|
| 81 | - $translations[$source][] = (string)$k; |
|
| 82 | - $translations[$source][] = array_key_exists('note', $unit) ? (string)$unit['note'] : ''; |
|
| 79 | + $source=(string) $unit['source']; |
|
| 80 | + $translations[$source][]=(string) $unit['target']; |
|
| 81 | + $translations[$source][]=(string) $k; |
|
| 82 | + $translations[$source][]=array_key_exists('note', $unit) ? (string) $unit['note'] : ''; |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | return $translations; |
@@ -124,22 +124,22 @@ discard block |
||
| 124 | 124 | */ |
| 125 | 125 | protected function getCatalogueList($catalogue) |
| 126 | 126 | { |
| 127 | - $variants = explode('_',$this->culture); |
|
| 128 | - $source = $catalogue.$this->dataExt; |
|
| 129 | - $catalogues = array($source); |
|
| 130 | - $variant = null; |
|
| 127 | + $variants=explode('_', $this->culture); |
|
| 128 | + $source=$catalogue.$this->dataExt; |
|
| 129 | + $catalogues=array($source); |
|
| 130 | + $variant=null; |
|
| 131 | 131 | |
| 132 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
| 132 | + for($i=0, $k=count($variants); $i < $k; ++$i) |
|
| 133 | 133 | { |
| 134 | 134 | if(isset($variants[$i]{0})) |
| 135 | 135 | { |
| 136 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
| 137 | - $catalogues[] = $catalogue.$this->dataSeparator.$variant.$this->dataExt; |
|
| 136 | + $variant.=($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
| 137 | + $catalogues[]=$catalogue.$this->dataSeparator.$variant.$this->dataExt; |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $byDir = $this->getCatalogueByDir($catalogue); |
|
| 142 | - return array_merge($byDir,array_reverse($catalogues)); |
|
| 141 | + $byDir=$this->getCatalogueByDir($catalogue); |
|
| 142 | + return array_merge($byDir, array_reverse($catalogues)); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -151,16 +151,16 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | private function getCatalogueByDir($catalogue) |
| 153 | 153 | { |
| 154 | - $variants = explode('_',$this->culture); |
|
| 155 | - $catalogues = array(); |
|
| 156 | - $variant = null; |
|
| 154 | + $variants=explode('_', $this->culture); |
|
| 155 | + $catalogues=array(); |
|
| 156 | + $variant=null; |
|
| 157 | 157 | |
| 158 | - for($i = 0, $k = count($variants); $i < $k; ++$i) |
|
| 158 | + for($i=0, $k=count($variants); $i < $k; ++$i) |
|
| 159 | 159 | { |
| 160 | 160 | if(isset($variants[$i]{0})) |
| 161 | 161 | { |
| 162 | - $variant .= ($variant)?'_'.$variants[$i]:$variants[$i]; |
|
| 163 | - $catalogues[] = $variant.'/'.$catalogue.$this->dataExt; |
|
| 162 | + $variant.=($variant) ? '_'.$variants[$i] : $variants[$i]; |
|
| 163 | + $catalogues[]=$variant.'/'.$catalogue.$this->dataExt; |
|
| 164 | 164 | } |
| 165 | 165 | } |
| 166 | 166 | |
@@ -184,38 +184,38 @@ discard block |
||
| 184 | 184 | * E.g. array('messages','en_AU') |
| 185 | 185 | * @return array list of catalogues |
| 186 | 186 | */ |
| 187 | - protected function getCatalogues($dir=null,$variant=null) |
|
| 187 | + protected function getCatalogues($dir=null, $variant=null) |
|
| 188 | 188 | { |
| 189 | - $dir = $dir?$dir:$this->source; |
|
| 190 | - $files = scandir($dir); |
|
| 191 | - $catalogue = array(); |
|
| 189 | + $dir=$dir ? $dir : $this->source; |
|
| 190 | + $files=scandir($dir); |
|
| 191 | + $catalogue=array(); |
|
| 192 | 192 | |
| 193 | 193 | foreach($files as $file) |
| 194 | 194 | { |
| 195 | - if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/',$file)) { |
|
| 196 | - $catalogue = array_merge( |
|
| 195 | + if(is_dir($dir.'/'.$file) && preg_match('/^[a-z]{2}(_[A-Z]{2,3})?$/', $file)) { |
|
| 196 | + $catalogue=array_merge( |
|
| 197 | 197 | $catalogue, |
| 198 | 198 | $this->getCatalogues($dir.'/'.$file, $file) |
| 199 | 199 | ); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - $pos = strpos($file,$this->dataExt); |
|
| 203 | - if($pos >0 && substr($file, -1*strlen($this->dataExt)) == $this->dataExt) |
|
| 202 | + $pos=strpos($file, $this->dataExt); |
|
| 203 | + if($pos > 0 && substr($file, -1 * strlen($this->dataExt))==$this->dataExt) |
|
| 204 | 204 | { |
| 205 | - $name = substr($file,0,$pos); |
|
| 206 | - $dot = strrpos($name,$this->dataSeparator); |
|
| 207 | - $culture = $variant; |
|
| 208 | - $cat = $name; |
|
| 205 | + $name=substr($file, 0, $pos); |
|
| 206 | + $dot=strrpos($name, $this->dataSeparator); |
|
| 207 | + $culture=$variant; |
|
| 208 | + $cat=$name; |
|
| 209 | 209 | |
| 210 | 210 | if(is_int($dot)) |
| 211 | 211 | { |
| 212 | - $culture = substr($name, $dot+1, strlen($name)); |
|
| 213 | - $cat = substr($name, 0, $dot); |
|
| 212 | + $culture=substr($name, $dot + 1, strlen($name)); |
|
| 213 | + $cat=substr($name, 0, $dot); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - $details[0] = $cat; |
|
| 217 | - $details[1] = $culture; |
|
| 218 | - $catalogue[] = $details; |
|
| 216 | + $details[0]=$cat; |
|
| 217 | + $details[1]=$culture; |
|
| 218 | + $catalogue[]=$details; |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | sort($catalogue); |
@@ -232,13 +232,13 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | private function getVariants($catalogue='messages') |
| 234 | 234 | { |
| 235 | - if($catalogue === null) { |
|
| 236 | - $catalogue = 'messages'; |
|
| 235 | + if($catalogue===null) { |
|
| 236 | + $catalogue='messages'; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | foreach($this->getCatalogueList($catalogue) as $variant) |
| 240 | 240 | { |
| 241 | - $file = $this->getSource($variant); |
|
| 241 | + $file=$this->getSource($variant); |
|
| 242 | 242 | if(is_file($file)) { |
| 243 | 243 | return array($variant, $file); |
| 244 | 244 | } |
@@ -248,10 +248,10 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | protected function internalSaveFile($php, $filename) |
| 250 | 250 | { |
| 251 | - $php['info']['date'] = @date('Y-m-d\TH:i:s\Z'); |
|
| 251 | + $php['info']['date']=@date('Y-m-d\TH:i:s\Z'); |
|
| 252 | 252 | |
| 253 | 253 | //save it and clear the cache for this variant |
| 254 | - if(false === file_put_contents($filename, "<?php\nreturn " . var_export($php, true) . ';')) |
|
| 254 | + if(false===file_put_contents($filename, "<?php\nreturn ".var_export($php, true).';')) |
|
| 255 | 255 | return false; |
| 256 | 256 | |
| 257 | 257 | if(!empty($this->cache)) |
@@ -269,30 +269,30 @@ discard block |
||
| 269 | 269 | */ |
| 270 | 270 | public function save($catalogue='messages') |
| 271 | 271 | { |
| 272 | - $messages = $this->untranslated; |
|
| 272 | + $messages=$this->untranslated; |
|
| 273 | 273 | if(count($messages) <= 0) { |
| 274 | 274 | return false; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $variants = $this->getVariants($catalogue); |
|
| 277 | + $variants=$this->getVariants($catalogue); |
|
| 278 | 278 | |
| 279 | 279 | if($variants) { |
| 280 | - list($variant, $filename) = $variants; |
|
| 280 | + list($variant, $filename)=$variants; |
|
| 281 | 281 | } else { |
| 282 | - list($variant, $filename) = $this->createMessageTemplate($catalogue); |
|
| 282 | + list($variant, $filename)=$this->createMessageTemplate($catalogue); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - if(is_writable($filename) == false) { |
|
| 285 | + if(is_writable($filename)==false) { |
|
| 286 | 286 | throw new TIOException("Unable to save to file {$filename}, file must be writable."); |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | //import the existing php file |
| 290 | - $php = include($filename); |
|
| 290 | + $php=include($filename); |
|
| 291 | 291 | |
| 292 | 292 | //for each message add it to the XML file using DOM |
| 293 | 293 | foreach($messages as $message) |
| 294 | 294 | { |
| 295 | - $php['trans-unit'][]= array( |
|
| 295 | + $php['trans-unit'][]=array( |
|
| 296 | 296 | 'source' => $message, |
| 297 | 297 | 'target' => '', |
| 298 | 298 | ); |
@@ -311,29 +311,29 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | public function update($text, $target, $comments, $catalogue='messages') |
| 313 | 313 | { |
| 314 | - $variants = $this->getVariants($catalogue); |
|
| 314 | + $variants=$this->getVariants($catalogue); |
|
| 315 | 315 | |
| 316 | 316 | if($variants) { |
| 317 | - list($variant, $filename) = $variants; |
|
| 317 | + list($variant, $filename)=$variants; |
|
| 318 | 318 | } else { |
| 319 | 319 | return false; |
| 320 | 320 | } |
| 321 | 321 | |
| 322 | - if(is_writable($filename) == false) { |
|
| 322 | + if(is_writable($filename)==false) { |
|
| 323 | 323 | throw new TIOException("Unable to update file {$filename}, file must be writable."); |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | //import the existing php file |
| 327 | - $php = include($filename); |
|
| 327 | + $php=include($filename); |
|
| 328 | 328 | |
| 329 | 329 | //for each of the existin units |
| 330 | 330 | foreach($php['trans-unit'] as $k => $unit) |
| 331 | 331 | { |
| 332 | - if($unit['source'] == $text) |
|
| 332 | + if($unit['source']==$text) |
|
| 333 | 333 | { |
| 334 | - $php['trans-unit'][$k]['target'] = $target; |
|
| 334 | + $php['trans-unit'][$k]['target']=$target; |
|
| 335 | 335 | if(!empty($comments)) |
| 336 | - $php['trans-unit'][$k]['note'] = $comments; |
|
| 336 | + $php['trans-unit'][$k]['note']=$comments; |
|
| 337 | 337 | |
| 338 | 338 | break; |
| 339 | 339 | } |
@@ -350,24 +350,24 @@ discard block |
||
| 350 | 350 | */ |
| 351 | 351 | public function delete($message, $catalogue='messages') |
| 352 | 352 | { |
| 353 | - $variants = $this->getVariants($catalogue); |
|
| 353 | + $variants=$this->getVariants($catalogue); |
|
| 354 | 354 | if($variants) { |
| 355 | - list($variant, $filename) = $variants; |
|
| 355 | + list($variant, $filename)=$variants; |
|
| 356 | 356 | } else { |
| 357 | 357 | return false; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - if(is_writable($filename) == false) { |
|
| 360 | + if(is_writable($filename)==false) { |
|
| 361 | 361 | throw new TIOException("Unable to modify file {$filename}, file must be writable."); |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | //import the existing php file |
| 365 | - $php = include($filename); |
|
| 365 | + $php=include($filename); |
|
| 366 | 366 | |
| 367 | 367 | //for each of the existin units |
| 368 | 368 | foreach($php['trans-unit'] as $k => $unit) |
| 369 | 369 | { |
| 370 | - if($unit['source'] == $message) |
|
| 370 | + if($unit['source']==$message) |
|
| 371 | 371 | { |
| 372 | 372 | unset($php['trans-unit'][$k]); |
| 373 | 373 | return $this->internalSaveFile($php, $filename); |
@@ -379,18 +379,18 @@ discard block |
||
| 379 | 379 | |
| 380 | 380 | protected function createMessageTemplate($catalogue) |
| 381 | 381 | { |
| 382 | - if($catalogue === null) { |
|
| 383 | - $catalogue = 'messages'; |
|
| 382 | + if($catalogue===null) { |
|
| 383 | + $catalogue='messages'; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - $variants = $this->getCatalogueList($catalogue); |
|
| 387 | - $variant = array_shift($variants); |
|
| 388 | - $file = $this->getSource($variant); |
|
| 389 | - $dir = dirname($file); |
|
| 386 | + $variants=$this->getCatalogueList($catalogue); |
|
| 387 | + $variant=array_shift($variants); |
|
| 388 | + $file=$this->getSource($variant); |
|
| 389 | + $dir=dirname($file); |
|
| 390 | 390 | |
| 391 | 391 | if(!is_dir($dir)) { |
| 392 | 392 | @mkdir($dir); |
| 393 | - @chmod($dir,PRADO_CHMOD); |
|
| 393 | + @chmod($dir, PRADO_CHMOD); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | if(!is_dir($dir)) { |
@@ -405,8 +405,8 @@ discard block |
||
| 405 | 405 | |
| 406 | 406 | protected function getTemplate($catalogue) |
| 407 | 407 | { |
| 408 | - $date = @date('Y-m-d\TH:i:s\Z'); |
|
| 409 | - $php = <<<EOD |
|
| 408 | + $date=@date('Y-m-d\TH:i:s\Z'); |
|
| 409 | + $php=<<<EOD |
|
| 410 | 410 | <?php |
| 411 | 411 | return array( |
| 412 | 412 | 'info' => array( |
@@ -19,7 +19,6 @@ |
||
| 19 | 19 | namespace Prado\I18N\core; |
| 20 | 20 | |
| 21 | 21 | use DOMDocument; |
| 22 | -use DOMXPath; |
|
| 23 | 22 | use Prado\Exceptions\TException; |
| 24 | 23 | use Prado\Exceptions\TIOException; |
| 25 | 24 | |
@@ -33,13 +33,13 @@ discard block |
||
| 33 | 33 | * Default character set is 'UTF-8'. |
| 34 | 34 | * @var string |
| 35 | 35 | */ |
| 36 | - private $_defaultCharset = 'UTF-8'; |
|
| 36 | + private $_defaultCharset='UTF-8'; |
|
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * Default culture is 'en'. |
| 40 | 40 | * @var string |
| 41 | 41 | */ |
| 42 | - private $_defaultCulture = 'en'; |
|
| 42 | + private $_defaultCulture='en'; |
|
| 43 | 43 | |
| 44 | 44 | /** |
| 45 | 45 | * The current charset. |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | if($config!==null) |
| 82 | 82 | { |
| 83 | 83 | if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) |
| 84 | - $translation = isset($config['translate'])?$config['translate']:null; |
|
| 84 | + $translation=isset($config['translate']) ? $config['translate'] : null; |
|
| 85 | 85 | else |
| 86 | 86 | { |
| 87 | - $t = $config->getElementByTagName('translation'); |
|
| 88 | - $translation = ($t)?$t->getAttributes():null; |
|
| 87 | + $t=$config->getElementByTagName('translation'); |
|
| 88 | + $translation=($t) ? $t->getAttributes() : null; |
|
| 89 | 89 | } |
| 90 | 90 | if($translation) |
| 91 | 91 | $this->setTranslationConfiguration($translation); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function setTranslateDefaultCulture($value) |
| 108 | 108 | { |
| 109 | - $this->_translateDefaultCulture = TPropertyValue::ensureBoolean($value); |
|
| 109 | + $this->_translateDefaultCulture=TPropertyValue::ensureBoolean($value); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function setDefaultCulture($culture) |
| 124 | 124 | { |
| 125 | - $this->_defaultCulture = str_replace('-','_',$culture); |
|
| 125 | + $this->_defaultCulture=str_replace('-', '_', $culture); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | public function setDefaultCharset($charset) |
| 140 | 140 | { |
| 141 | - $this->_defaultCharset = $charset; |
|
| 141 | + $this->_defaultCharset=$charset; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | public function setCulture($culture) |
| 156 | 156 | { |
| 157 | - $this->_culture = str_replace('-','_',$culture); |
|
| 157 | + $this->_culture=str_replace('-', '_', $culture); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function setCharset($charset) |
| 172 | 172 | { |
| 173 | - $this->_charset = $charset; |
|
| 173 | + $this->_charset=$charset; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function getTranslationConfiguration() |
| 180 | 180 | { |
| 181 | - return (!$this->_translateDefaultCulture && ($this->getDefaultCulture() == $this->getCulture())) |
|
| 181 | + return (!$this->_translateDefaultCulture && ($this->getDefaultCulture()==$this->getCulture())) |
|
| 182 | 182 | ? null |
| 183 | 183 | : $this->_translation; |
| 184 | 184 | } |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | protected function setTranslationConfiguration($config) |
| 202 | 202 | { |
| 203 | - if($config['type'] == 'XLIFF' || $config['type'] == 'gettext' || $config['type'] == 'PHP') |
|
| 203 | + if($config['type']=='XLIFF' || $config['type']=='gettext' || $config['type']=='PHP') |
|
| 204 | 204 | { |
| 205 | 205 | if($config['source']) |
| 206 | 206 | { |
| 207 | - $config['source'] = Prado::getPathOfNamespace($config['source']); |
|
| 207 | + $config['source']=Prado::getPathOfNamespace($config['source']); |
|
| 208 | 208 | if(!is_dir($config['source'])) |
| 209 | 209 | { |
| 210 | 210 | if(@mkdir($config['source'])===false) |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | } |
| 221 | 221 | if(isset($config['cache']) && TPropertyValue::ensureBoolean($config['cache'])) |
| 222 | 222 | { |
| 223 | - $config['cache'] = $this->getApplication()->getRunTimePath().'/i18n'; |
|
| 223 | + $config['cache']=$this->getApplication()->getRunTimePath().'/i18n'; |
|
| 224 | 224 | if(!is_dir($config['cache'])) |
| 225 | 225 | { |
| 226 | 226 | if(@mkdir($config['cache'])===false) |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | { |
| 234 | 234 | unset($config['cache']); |
| 235 | 235 | } |
| 236 | - $this->_translation = $config; |
|
| 236 | + $this->_translation=$config; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | public function setTranslationCatalogue($value) |
| 251 | 251 | { |
| 252 | - $this->_translation['catalogue'] = $value; |
|
| 252 | + $this->_translation['catalogue']=$value; |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | /** |
@@ -260,11 +260,11 @@ discard block |
||
| 260 | 260 | */ |
| 261 | 261 | public function getCultureVariants($culture=null) |
| 262 | 262 | { |
| 263 | - if($culture===null) $culture = $this->getCulture(); |
|
| 264 | - $variants = explode('_', $culture); |
|
| 265 | - $result = array(); |
|
| 263 | + if($culture===null) $culture=$this->getCulture(); |
|
| 264 | + $variants=explode('_', $culture); |
|
| 265 | + $result=array(); |
|
| 266 | 266 | for(; count($variants) > 0; array_pop($variants)) |
| 267 | - $result[] = implode('_', $variants); |
|
| 267 | + $result[]=implode('_', $variants); |
|
| 268 | 268 | return $result; |
| 269 | 269 | } |
| 270 | 270 | |
@@ -287,17 +287,17 @@ discard block |
||
| 287 | 287 | * @param string culture string, null to use current culture |
| 288 | 288 | * @return array list of possible localized resource files. |
| 289 | 289 | */ |
| 290 | - public function getLocalizedResource($file,$culture=null) |
|
| 290 | + public function getLocalizedResource($file, $culture=null) |
|
| 291 | 291 | { |
| 292 | - $files = array(); |
|
| 293 | - $variants = $this->getCultureVariants($culture); |
|
| 294 | - $path = pathinfo($file); |
|
| 292 | + $files=array(); |
|
| 293 | + $variants=$this->getCultureVariants($culture); |
|
| 294 | + $path=pathinfo($file); |
|
| 295 | 295 | foreach($variants as $variant) |
| 296 | - $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$variant.DIRECTORY_SEPARATOR.$path['basename']; |
|
| 297 | - $filename = substr($path['basename'],0,strrpos($path['basename'],'.')); |
|
| 296 | + $files[]=$path['dirname'].DIRECTORY_SEPARATOR.$variant.DIRECTORY_SEPARATOR.$path['basename']; |
|
| 297 | + $filename=substr($path['basename'], 0, strrpos($path['basename'], '.')); |
|
| 298 | 298 | foreach($variants as $variant) |
| 299 | - $files[] = $path['dirname'].DIRECTORY_SEPARATOR.$filename.'.'.$variant.'.'.$path['extension']; |
|
| 300 | - $files[] = $file; |
|
| 299 | + $files[]=$path['dirname'].DIRECTORY_SEPARATOR.$filename.'.'.$variant.'.'.$path['extension']; |
|
| 300 | + $files[]=$file; |
|
| 301 | 301 | return $files; |
| 302 | 302 | } |
| 303 | 303 | |
@@ -111,15 +111,15 @@ |
||
| 111 | 111 | /** |
| 112 | 112 | * Factory method to instantiate a new MessageSource depending on the |
| 113 | 113 | * source type. The allowed source types are 'XLIFF', 'PHP', 'gettext' and |
| 114 | - * 'Database'. The source parameter depends on the source type. |
|
| 115 | - * For 'gettext', 'PHP' and 'XLIFF', 'source' should point to the directory |
|
| 116 | - * where the messages are stored. |
|
| 117 | - * For 'Database', 'source' must be a valid connection id. |
|
| 118 | - * If a deprecated 'SQLite' type is used, 'source' must contain |
|
| 119 | - * a valid DSN. |
|
| 114 | + * 'Database'. The source parameter depends on the source type. |
|
| 115 | + * For 'gettext', 'PHP' and 'XLIFF', 'source' should point to the directory |
|
| 116 | + * where the messages are stored. |
|
| 117 | + * For 'Database', 'source' must be a valid connection id. |
|
| 118 | + * If a deprecated 'SQLite' type is used, 'source' must contain |
|
| 119 | + * a valid DSN. |
|
| 120 | 120 | * |
| 121 | - * Custom message source are possible by supplying the a filename parameter |
|
| 122 | - * in the factory method. |
|
| 121 | + * Custom message source are possible by supplying the a filename parameter |
|
| 122 | + * in the factory method. |
|
| 123 | 123 | * |
| 124 | 124 | * @param string the message source type. |
| 125 | 125 | * @param string the location of the resource or the ConnectionID. |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * Array of translation messages. |
| 84 | 84 | * @var array |
| 85 | 85 | */ |
| 86 | - protected $messages = array(); |
|
| 86 | + protected $messages=array(); |
|
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * The source of message translations. |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | protected $cache; |
| 99 | 99 | |
| 100 | - protected $untranslated = array(); |
|
| 100 | + protected $untranslated=array(); |
|
| 101 | 101 | |
| 102 | 102 | /** |
| 103 | 103 | * Private constructor. MessageSource must be initialized using |
@@ -129,23 +129,23 @@ discard block |
||
| 129 | 129 | */ |
| 130 | 130 | static function &factory($type, $source='.', $filename='') |
| 131 | 131 | { |
| 132 | - $types = array('XLIFF','PHP','gettext','Database','SQLite'); |
|
| 132 | + $types=array('XLIFF', 'PHP', 'gettext', 'Database', 'SQLite'); |
|
| 133 | 133 | |
| 134 | 134 | if(empty($filename) && !in_array($type, $types)) |
| 135 | 135 | throw new Exception('Invalid type "'.$type.'", valid types are '. |
| 136 | 136 | implode(', ', $types)); |
| 137 | 137 | |
| 138 | - $class = 'MessageSource_'.$type; |
|
| 138 | + $class='MessageSource_'.$type; |
|
| 139 | 139 | |
| 140 | 140 | if(empty($filename)) |
| 141 | - $filename = dirname(__FILE__).'/'.$class.'.php'; |
|
| 141 | + $filename=dirname(__FILE__).'/'.$class.'.php'; |
|
| 142 | 142 | |
| 143 | - if(is_file($filename) == false) |
|
| 143 | + if(is_file($filename)==false) |
|
| 144 | 144 | throw new Exception("File $filename not found"); |
| 145 | 145 | |
| 146 | 146 | include_once $filename; |
| 147 | 147 | |
| 148 | - $obj = new $class($source); |
|
| 148 | + $obj=new $class($source); |
|
| 149 | 149 | |
| 150 | 150 | return $obj; |
| 151 | 151 | } |
@@ -171,36 +171,36 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | function load($catalogue='messages') |
| 173 | 173 | { |
| 174 | - $variants = $this->getCatalogueList($catalogue); |
|
| 174 | + $variants=$this->getCatalogueList($catalogue); |
|
| 175 | 175 | |
| 176 | - $this->messages = array(); |
|
| 176 | + $this->messages=array(); |
|
| 177 | 177 | |
| 178 | 178 | foreach($variants as $variant) |
| 179 | 179 | { |
| 180 | - $source = $this->getSource($variant); |
|
| 180 | + $source=$this->getSource($variant); |
|
| 181 | 181 | |
| 182 | - if($this->isValidSource($source) == false) continue; |
|
| 182 | + if($this->isValidSource($source)==false) continue; |
|
| 183 | 183 | |
| 184 | - $loadData = true; |
|
| 184 | + $loadData=true; |
|
| 185 | 185 | |
| 186 | 186 | if($this->cache) |
| 187 | 187 | { |
| 188 | - $data = $this->cache->get($variant, |
|
| 188 | + $data=$this->cache->get($variant, |
|
| 189 | 189 | $this->culture, $this->getLastModified($source)); |
| 190 | 190 | |
| 191 | 191 | if(is_array($data)) |
| 192 | 192 | { |
| 193 | - $this->messages[$variant] = $data; |
|
| 194 | - $loadData = false; |
|
| 193 | + $this->messages[$variant]=$data; |
|
| 194 | + $loadData=false; |
|
| 195 | 195 | } |
| 196 | 196 | unset($data); |
| 197 | 197 | } |
| 198 | 198 | if($loadData) |
| 199 | 199 | { |
| 200 | - $data = &$this->loadData($source); |
|
| 200 | + $data=&$this->loadData($source); |
|
| 201 | 201 | if(is_array($data)) |
| 202 | 202 | { |
| 203 | - $this->messages[$variant] = $data; |
|
| 203 | + $this->messages[$variant]=$data; |
|
| 204 | 204 | if($this->cache) |
| 205 | 205 | $this->cache->save($data, $variant, $this->culture); |
| 206 | 206 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | */ |
| 237 | 237 | public function setCache(MessageCache $cache) |
| 238 | 238 | { |
| 239 | - $this->cache = $cache; |
|
| 239 | + $this->cache=$cache; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function append($message) |
| 248 | 248 | { |
| 249 | 249 | if(!in_array($message, $this->untranslated)) |
| 250 | - $this->untranslated[] = $message; |
|
| 250 | + $this->untranslated[]=$message; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function setCulture($culture) |
| 258 | 258 | { |
| 259 | - $this->culture = $culture; |
|
| 259 | + $this->culture=$culture; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |