Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MessageGroupOld.php
Go to the documentation of this file.
1<?php
16
23abstract class MessageGroupOld implements MessageGroup {
27 protected $label = 'none';
28
33 public function getLabel( IContextSource $context = null ) {
34 return $this->label;
35 }
36
38 public function setLabel( $value ) {
39 $this->label = $value;
40 }
41
45 protected $id = 'none';
46
48 public function getId() {
49 return $this->id;
50 }
51
53 public function setId( $value ) {
54 $this->id = $value;
55 }
56
62 protected $namespace = NS_MEDIAWIKI;
63
68 public function getNamespace() {
69 return $this->namespace;
70 }
71
76 public function setNamespace( $ns ) {
77 $this->namespace = $ns;
78 }
79
84 protected $description = null;
85
86 public function getDescription( IContextSource $context = null ) {
87 return $this->description;
88 }
89
90 public function setDescription( $value ) {
91 $this->description = $value;
92 }
93
94 public function getIcon() {
95 return null;
96 }
97
102 protected $meta = false;
103
104 public function isMeta() {
105 return $this->meta;
106 }
107
108 public function getSourceLanguage() {
109 return 'en';
110 }
111
116 protected $mangler = null;
117
119 public function getMangler() {
120 if ( !isset( $this->mangler ) ) {
121 $this->mangler = new StringMatcher();
122 }
123
124 return $this->mangler;
125 }
126
127 public function load( $code ) {
128 return [];
129 }
130
138 public function getDefinitions() {
139 $defs = $this->load( $this->getSourceLanguage() );
140 if ( !is_array( $defs ) ) {
141 throw new MWException( 'Unable to load definitions for ' . $this->getLabel() );
142 }
143
144 return $defs;
145 }
146
153 public function getUniqueDefinitions() {
154 return $this->meta ? [] : $this->getDefinitions();
155 }
156
158 public function getKeys() {
159 return array_keys( $this->getDefinitions() );
160 }
161
170 public function getMessage( $key, $code ) {
171 if ( !isset( $this->messages[$code] ) ) {
172 $this->messages[$code] = self::normaliseKeys( $this->load( $code ) );
173 }
174 $key = strtolower( str_replace( ' ', '_', $key ) );
175
176 return $this->messages[$code][$key] ?? null;
177 }
178
179 public static function normaliseKeys( $array ) {
180 if ( !is_array( $array ) ) {
181 return null;
182 }
183
184 $new = [];
185 foreach ( $array as $key => $v ) {
186 $key = strtolower( str_replace( ' ', '_', $key ) );
187 $new[$key] = $v;
188 }
189
190 return $new;
191 }
192
196 protected $messages = [];
197
204 public function getMessageFile( $code ) {
205 return false;
206 }
207
208 public function getPath() {
209 return false;
210 }
211
216 public function getMessageFileWithPath( $code ) {
217 $path = $this->getPath();
218 $file = $this->getMessageFile( $code );
219
220 if ( !$path || !$file ) {
221 return false;
222 }
223
224 return "$path/$file";
225 }
226
227 public function getSourceFilePath( $code ) {
228 return $this->getMessageFileWithPath( $code );
229 }
230
239 public function initCollection( $code, $unique = false ) {
240 if ( !$unique ) {
241 $definitions = $this->getDefinitions();
242 } else {
243 $definitions = $this->getUniqueDefinitions();
244 }
245
246 $defs = new MessageDefinitions( $definitions, $this->getNamespace() );
247 $collection = MessageCollection::newFromDefinitions( $defs, $code );
248
249 foreach ( $this->getTags() as $type => $tags ) {
250 $collection->setTags( $type, $tags );
251 }
252
253 return $collection;
254 }
255
260 public function exists() {
261 return true;
262 }
263
264 public function getValidator() {
265 return null;
266 }
267
268 public function getTags( $type = null ) {
269 return [];
270 }
271
276 protected function isSourceLanguage( $code ) {
277 return $code === $this->getSourceLanguage();
278 }
279
284 public function getMessageGroupStates() {
285 global $wgTranslateWorkflowStates;
286 $conf = $wgTranslateWorkflowStates ?: [];
287
288 Hooks::run( 'Translate:modifyMessageGroupStates', [ $this->getId(), &$conf ] );
289
290 return new MessageGroupStates( $conf );
291 }
292
294 public function getTranslatableLanguages() {
295 return null;
296 }
297
298 protected static function addContext( Message $message, IContextSource $context = null ) {
299 if ( $context ) {
300 $message->inLanguage( $context->getLanguage() );
301 } else {
302 $message->inLanguage( 'en' );
303 }
304
305 return $message;
306 }
307
314 public function getTranslationAids() {
315 return TranslationAid::getTypes();
316 }
317
318 public function getSupportConfig(): ?array {
319 return null;
320 }
321}
return[ 'Translate:ConfigHelper'=> static function():ConfigHelper { return new ConfigHelper();}, 'Translate:CsvTranslationImporter'=> static function(MediaWikiServices $services):CsvTranslationImporter { return new CsvTranslationImporter( $services->getWikiPageFactory());}, 'Translate:EntitySearch'=> static function(MediaWikiServices $services):EntitySearch { return new EntitySearch($services->getMainWANObjectCache(), $services->getCollationFactory() ->makeCollation( 'uca-default-u-kn'), MessageGroups::singleton(), $services->getNamespaceInfo(), $services->get( 'Translate:MessageIndex'), $services->getTitleParser(), $services->getTitleFormatter());}, 'Translate:ExternalMessageSourceStateImporter'=> static function(MediaWikiServices $services):ExternalMessageSourceStateImporter { return new ExternalMessageSourceStateImporter($services->getMainConfig(), $services->get( 'Translate:GroupSynchronizationCache'), $services->getJobQueueGroup(), LoggerFactory::getInstance( 'Translate.GroupSynchronization'), MessageIndex::singleton());}, 'Translate:GroupSynchronizationCache'=> static function(MediaWikiServices $services):GroupSynchronizationCache { return new GroupSynchronizationCache( $services->get( 'Translate:PersistentCache'));}, 'Translate:MessageBundleStore'=> static function(MediaWikiServices $services):MessageBundleStore { return new MessageBundleStore(new RevTagStore(), $services->getJobQueueGroup(), $services->getLanguageNameUtils(), $services->get( 'Translate:MessageIndex'));}, 'Translate:MessageGroupReview'=> static function(MediaWikiServices $services):MessageGroupReview { return new MessageGroupReview($services->getDBLoadBalancer(), $services->getHookContainer());}, 'Translate:MessageIndex'=> static function(MediaWikiServices $services):MessageIndex { $params=$services->getMainConfig() ->get( 'TranslateMessageIndex');if(is_string( $params)) { $params=(array) $params;} $class=array_shift( $params);return new $class( $params);}, 'Translate:ParsingPlaceholderFactory'=> static function():ParsingPlaceholderFactory { return new ParsingPlaceholderFactory();}, 'Translate:PersistentCache'=> static function(MediaWikiServices $services):PersistentCache { return new PersistentDatabaseCache($services->getDBLoadBalancer(), $services->getJsonCodec());}, 'Translate:ProgressStatsTableFactory'=> static function(MediaWikiServices $services):ProgressStatsTableFactory { return new ProgressStatsTableFactory($services->getLinkRenderer(), $services->get( 'Translate:ConfigHelper'));}, 'Translate:SubpageListBuilder'=> static function(MediaWikiServices $services):SubpageListBuilder { return new SubpageListBuilder($services->get( 'Translate:TranslatableBundleFactory'), $services->getLinkBatchFactory());}, 'Translate:TranslatableBundleFactory'=> static function(MediaWikiServices $services):TranslatableBundleFactory { return new TranslatableBundleFactory($services->get( 'Translate:TranslatablePageStore'), $services->get( 'Translate:MessageBundleStore'));}, 'Translate:TranslatableBundleMover'=> static function(MediaWikiServices $services):TranslatableBundleMover { return new TranslatableBundleMover($services->getMovePageFactory(), $services->getJobQueueGroup(), $services->getLinkBatchFactory(), $services->get( 'Translate:TranslatableBundleFactory'), $services->get( 'Translate:SubpageListBuilder'), $services->getMainConfig() ->get( 'TranslatePageMoveLimit'));}, 'Translate:TranslatablePageParser'=> static function(MediaWikiServices $services):TranslatablePageParser { return new TranslatablePageParser($services->get( 'Translate:ParsingPlaceholderFactory'));}, 'Translate:TranslatablePageStore'=> static function(MediaWikiServices $services):TranslatablePageStore { return new TranslatablePageStore($services->get( 'Translate:MessageIndex'), $services->getJobQueueGroup(), new RevTagStore(), $services->getDBLoadBalancer());}, 'Translate:TranslationStashReader'=> static function(MediaWikiServices $services):TranslationStashReader { $db=$services->getDBLoadBalancer() ->getConnectionRef(DB_REPLICA);return new TranslationStashStorage( $db);}, 'Translate:TranslationStatsDataProvider'=> static function(MediaWikiServices $services):TranslationStatsDataProvider { return new TranslationStatsDataProvider(new ServiceOptions(TranslationStatsDataProvider::CONSTRUCTOR_OPTIONS, $services->getMainConfig()), $services->getObjectFactory());}, 'Translate:TranslationUnitStoreFactory'=> static function(MediaWikiServices $services):TranslationUnitStoreFactory { return new TranslationUnitStoreFactory( $services->getDBLoadBalancer());}, 'Translate:TranslatorActivity'=> static function(MediaWikiServices $services):TranslatorActivity { $query=new TranslatorActivityQuery($services->getMainConfig(), $services->getDBLoadBalancer());return new TranslatorActivity($services->getMainObjectStash(), $query, $services->getJobQueueGroup());}, 'Translate:TtmServerFactory'=> static function(MediaWikiServices $services):TtmServerFactory { $config=$services->getMainConfig();$default=$config->get( 'TranslateTranslationDefaultService');if( $default===false) { $default=null;} return new TtmServerFactory( $config->get( 'TranslateTranslationServices'), $default);}]
@phpcs-require-sorted-array
The versatile default implementation of StringMangler interface.
Wrapper for message definitions, just to beauty the code.
This is the interface and base implementation of unmanaged message groups.
getTags( $type=null)
Returns message tags.
getNamespace()
Get the namespace where all the messages of this group belong.
getTranslatableLanguages()
@inheritDoc
getKeys()
@inheritDoc
$description
Holds description of this group.
getMessageFileWithPath( $code)
getMessageFile( $code)
Returns path to the file where translation of language code $code are.
$meta
Meta groups consist of multiple groups or parts of other groups.
$mangler
To avoid key conflicts between groups or separated changed messages between branches one can set a me...
getLabel(IContextSource $context=null)
getDefinitions()
This function returns array of type key => definition of all messages this message group handles.
$namespace
The namespace where all the messages of this group belong.
initCollection( $code, $unique=false)
Creates a new MessageCollection for this group.
getDescription(IContextSource $context=null)
Returns a longer description about the group.
getMessage( $key, $code)
Returns of stored translation of message specified by the $key in language code $code.
setNamespace( $ns)
Set the namespace where all the messages of this group belong.
getSupportConfig()
Gets support URL defined for the group if any.
$id
Group-wide unique id of this group.
exists()
Can be overwritten to return false if something is wrong.
$messages
All the messages for this group, by language code.
getTranslationAids()
List of available message types mapped to the classes implementing them.
$label
Human-readable name of this group.
getSourceLanguage()
Returns language code depicting the language of source text.
load( $code)
Returns a list of messages in a given language code.
getValidator()
Returns a message validator object or null.
getIcon()
Returns an icon for this message group if any.
getUniqueDefinitions()
This function can be used for meta message groups to list their "own" messages.
getMessageGroupStates()
Get the message group workflow state configuration.
Class for making the use of message group state easier.
Interface for message groups.