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