TranslationAid.php

Go to the documentation of this file.
00001 <?php
00020 abstract class TranslationAid {
00024     protected $group;
00025 
00029     protected $handle;
00030 
00034     protected $context;
00035 
00036     public function __construct( MessageGroup $group, MessageHandle $handle,
00037         IContextSource $context
00038     ) {
00039         $this->group = $group;
00040         $this->handle = $handle;
00041         $this->context = $context;
00042     }
00043 
00057     abstract public function getData();
00058 
00064     public function getDefinition() {
00065         static $cache = array();
00066 
00067         $key = $this->handle->getTitle()->getPrefixedText();
00068 
00069         if ( array_key_exists( $key, $cache ) ) {
00070             return $cache[$key];
00071         }
00072 
00073         if ( method_exists( $this->group, 'getMessageContent' ) ) {
00074             $cache[$key] = $this->group->getMessageContent( $this->handle );
00075         } else {
00076             $cache[$key] = $this->group->getMessage(
00077                 $this->handle->getKey(),
00078                 $this->group->getSourceLanguage()
00079             );
00080         }
00081 
00082         return $cache[$key];
00083     }
00084 
00091     public function getTranslations() {
00092         static $cache = array();
00093 
00094         $key = $this->handle->getTitle()->getPrefixedText();
00095 
00096         if ( array_key_exists( $key, $cache ) ) {
00097             return $cache[$key];
00098         }
00099 
00100         $data = ApiQueryMessageTranslations::getTranslations( $this->handle );
00101         $namespace = $this->handle->getTitle()->getNamespace();
00102 
00103         $cache[$key] = array();
00104 
00105         foreach ( $data as $page => $info ) {
00106             $tTitle = Title::makeTitle( $namespace, $page );
00107             $tHandle = new MessageHandle( $tTitle );
00108 
00109             $fuzzy = MessageHandle::hasFuzzyString( $info[0] ) || $tHandle->isFuzzy();
00110             if ( $fuzzy ) {
00111                 continue;
00112             }
00113 
00114             $code = $tHandle->getCode();
00115             $cache[$key][$code] = $info[0];
00116         }
00117 
00118         return $cache[$key];
00119     }
00120 
00127     public static function getTypes() {
00128         $types = array(
00129             'definition' => 'MessageDefinitionAid',
00130             'translation' => 'CurrentTranslationAid',
00131             'inotherlanguages' => 'InOtherLanguagesAid',
00132             'documentation' => 'DocumentationAid',
00133             'mt' => 'MachineTranslationAid',
00134             'definitiondiff' => 'UpdatedDefinitionAid',
00135             'ttmserver' => 'TTMServerAid',
00136             'support' => 'SupportAid',
00137             'gettext' => 'GettextDocumentationAid',
00138             'insertables' => 'InsertablesAid',
00139         );
00140 
00141         return $types;
00142     }
00143 }
Generated on Tue Oct 29 00:00:25 2013 for MediaWiki Translate Extension by  doxygen 1.6.3