Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
WikiMessageGroup.php
Go to the documentation of this file.
1<?php
13
24 protected $source;
25
30 public function __construct( $id, $source ) {
31 $this->id = $id;
32 $this->source = $source;
33 }
34
39 public function getSourceLanguage() {
40 global $wgLanguageCode;
41
42 return $wgLanguageCode;
43 }
44
49 public function getDefinitions() {
50 $definitions = [];
51
52 // In theory the page could have templates that are substitued
53 $source = wfMessage( $this->source );
54 if ( $source->isDisabled() ) {
55 return [];
56 }
57
58 $contents = $source->text();
59 $contents = preg_replace( '~^\s*#.*$~m', '', $contents );
60 $messages = preg_split( '/\s+/', $contents );
61
62 foreach ( $messages as $message ) {
63 if ( !$message ) {
64 continue;
65 }
66
67 $definitions[$message] = wfMessage( $message )->inContentLanguage()->plain();
68 }
69
70 return $definitions;
71 }
72
81 public function getMessage( $key, $code ) {
82 if ( $code && $this->getSourceLanguage() !== $code ) {
83 return Utilities::getMessageContent( $key, $code );
84 } else {
85 return Utilities::getMessageContent( $key, '' );
86 }
87 }
88}
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.
$id
Group-wide unique id of this group.
$messages
All the messages for this group, by language code.
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.