MessageGroupOld.php

Go to the documentation of this file.
00001 <?php
00020 abstract class MessageGroupOld implements MessageGroup {
00024     protected $label = 'none';
00025 
00030     public function getLabel( IContextSource $context = null ) {
00031         return $this->label;
00032     }
00033 
00037     public function setLabel( $value ) {
00038         $this->label = $value;
00039     }
00040 
00044     protected $id = 'none';
00045 
00049     public function getId() {
00050         return $this->id;
00051     }
00052 
00056     public function setId( $value ) {
00057         $this->id = $value;
00058     }
00059 
00065     protected $namespace = NS_MEDIAWIKI;
00066 
00068     public function getNamespace() {
00069         return $this->namespace;
00070     }
00071 
00073     public function setNamespace( $ns ) {
00074         $this->namespace = $ns;
00075     }
00076 
00081     protected $optional = array();
00082 
00086     public function getOptional() {
00087         return $this->optional;
00088     }
00089 
00093     public function setOptional( $value ) {
00094         $this->optional = $value;
00095     }
00096 
00100     protected $ignored = array();
00101 
00105     public function getIgnored() {
00106         return $this->ignored;
00107     }
00108 
00112     public function setIgnored( $value ) {
00113         $this->ignored = $value;
00114     }
00115 
00120     protected $description = null;
00121 
00122     public function getDescription( IContextSource $context = null ) {
00123         return $this->description;
00124     }
00125 
00126     public function setDescription( $value ) {
00127         $this->description = $value;
00128     }
00129 
00130     public function getIcon() {
00131         return null;
00132     }
00133 
00138     protected $meta = false;
00139 
00140     public function isMeta() {
00141         return $this->meta;
00142     }
00143 
00144     public function setMeta( $value ) {
00145         $this->meta = $value;
00146     }
00147 
00148     public function getSourceLanguage() {
00149         return 'en';
00150     }
00151 
00156     protected $mangler = null;
00157 
00161     public function getMangler() {
00162         if ( !isset( $this->mangler ) ) {
00163             $this->mangler = StringMatcher::emptyMatcher();
00164         }
00165 
00166         return $this->mangler;
00167     }
00168 
00169     public function setMangler( $value ) {
00170         $this->mangler = $value;
00171     }
00172 
00173     public function getReader( $code ) {
00174         return null;
00175     }
00176 
00180     public function getWriter() {
00181         return new SimpleFormatWriter( $this );
00182     }
00183 
00184     public function load( $code ) {
00185         $reader = $this->getReader( $code );
00186         if ( $reader ) {
00187             $messages = $reader->parseMessages( $this->mangler );
00188 
00189             return $messages ? $messages : array();
00190         }
00191 
00192         return array();
00193     }
00194 
00202     public function getDefinitions() {
00203         $defs = $this->load( $this->getSourceLanguage() );
00204         if ( !is_array( $defs ) ) {
00205             throw new MWException( "Unable to load definitions for " . $this->getLabel() );
00206         }
00207 
00208         return $defs;
00209     }
00210 
00217     public function getUniqueDefinitions() {
00218         return $this->meta ? array() : $this->getDefinitions();
00219     }
00220 
00229     public function getMessage( $key, $code ) {
00230         if ( !isset( $this->messages[$code] ) ) {
00231             $this->messages[$code] = self::normaliseKeys( $this->load( $code ) );
00232         }
00233         $key = strtolower( str_replace( ' ', '_', $key ) );
00234 
00235         return isset( $this->messages[$code][$key] ) ? $this->messages[$code][$key] : null;
00236     }
00237 
00238     public static function normaliseKeys( $array ) {
00239         if ( !is_array( $array ) ) {
00240             return null;
00241         }
00242 
00243         $new = array();
00244         foreach ( $array as $key => $v ) {
00245             $key = strtolower( str_replace( ' ', '_', $key ) );
00246             $new[$key] = $v;
00247         }
00248 
00249         return $new;
00250     }
00251 
00255     private $messages = array();
00256 
00263     public function getMessageFile( $code ) {
00264         return false;
00265     }
00266 
00267     public function getPath() {
00268         return false;
00269     }
00270 
00275     public function getMessageFileWithPath( $code ) {
00276         $path = $this->getPath();
00277         $file = $this->getMessageFile( $code );
00278 
00279         if ( !$path || !$file ) {
00280             return false;
00281         }
00282 
00283         return "$path/$file";
00284     }
00285 
00286     public function getSourceFilePath( $code ) {
00287         return $this->getMessageFileWithPath( $code );
00288     }
00289 
00298     public function initCollection( $code, $unique = false ) {
00299         if ( !$unique ) {
00300             $definitions = $this->getDefinitions();
00301         } else {
00302             $definitions = $this->getUniqueDefinitions();
00303         }
00304 
00305         $defs = new MessageDefinitions( $definitions, $this->getNamespace() );
00306         $collection = MessageCollection::newFromDefinitions( $defs, $code );
00307 
00308         foreach ( $this->getTags() as $type => $tags ) {
00309             $collection->setTags( $type, $tags );
00310         }
00311 
00312         return $collection;
00313     }
00314 
00315     public function __construct() {
00316     }
00317 
00322     public function exists() {
00323         return true;
00324     }
00325 
00326     public function getChecker() {
00327         return null;
00328     }
00329 
00330     public function getTags( $type = null ) {
00331         $tags = array(
00332             'optional' => $this->optional,
00333             'ignored' => $this->ignored,
00334         );
00335 
00336         if ( !$type ) {
00337             return $tags;
00338         }
00339 
00340         return isset( $tags[$type] ) ? $tags[$type] : array();
00341     }
00342 
00347     protected function isSourceLanguage( $code ) {
00348         return $code === $this->getSourceLanguage();
00349     }
00350 
00351     // Unsupported stuff, just to satisfy the new interface
00352     public function setConfiguration( $conf ) {
00353     }
00354 
00355     public function getConfiguration() {
00356     }
00357 
00358     public function getFFS() {
00359         return null;
00360     }
00361 
00365     public function getWorkflowConfiguration() {
00366         global $wgTranslateWorkflowStates;
00367         if ( !$wgTranslateWorkflowStates ) {
00368             // Not configured
00369             $conf = array();
00370         } else {
00371             $conf = $wgTranslateWorkflowStates;
00372         }
00373 
00374         return $conf;
00375     }
00376 
00381     public function getMessageGroupStates() {
00382         $conf = $this->getWorkflowConfiguration();
00383 
00384         return new MessageGroupStates( $conf );
00385     }
00386 
00392     public function getTranslatableLanguages() {
00393         return null;
00394     }
00395 
00396     protected static function addContext( Message $message, IContextSource $context = null ) {
00397         if ( $context ) {
00398             $message->inLanguage( $context->getLanguage() );
00399         }
00400 
00401         return $message;
00402     }
00403 
00410     public function getTranslationAids() {
00411         return TranslationAid::getTypes();
00412     }
00413 }
Generated on Tue Oct 29 00:00:24 2013 for MediaWiki Translate Extension by  doxygen 1.6.3