Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
WikiMessageGroup.php
Go to the documentation of this file.
1<?php
13
25 protected $source;
26
31 public function __construct( $id, $source ) {
32 $this->id = $id;
33 $this->source = $source;
34 }
35
40 public function getSourceLanguage() {
41 global $wgLanguageCode;
42
43 return $wgLanguageCode;
44 }
45
50 public function getDefinitions() {
51 $definitions = [];
52
53 // In theory the page could have templates that are substitued
54 $source = wfMessage( $this->source );
55 if ( $source->isDisabled() ) {
56 return [];
57 }
58
59 $contents = $source->text();
60 $contents = preg_replace( '~^\s*#.*$~m', '', $contents );
61 $messages = preg_split( '/\s+/', $contents );
62
63 foreach ( $messages as $message ) {
64 if ( !$message ) {
65 continue;
66 }
67
68 $definitions[$message] = wfMessage( $message )->inContentLanguage()->plain();
69 }
70
71 return $definitions;
72 }
73
82 public function getMessage( $key, $code ) {
83 if ( $code && $this->getSourceLanguage() !== $code ) {
84 return Utilities::getMessageContent( $key, $code );
85 } else {
86 return Utilities::getMessageContent( $key, '' );
87 }
88 }
89}
Essentially random collection of helper functions, similar to GlobalFunctions.php.
Definition Utilities.php:31
This is the interface and base implementation of unmanaged message groups.
Group for messages that can be controlled via a page in MediaWiki namespace.
getSourceLanguage()
Defaults to wiki content language.
getDefinitions()
Fetch definitions from database.
__construct( $id, $source)
getMessage( $key, $code)
Returns of stored translation of message specified by the $key in language code $code.