Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
Message.php
Go to the documentation of this file.
1<?php
14abstract class TMessage {
16 protected $key;
18 protected $definition;
20 protected $infile;
22 protected $tags = [];
24 protected $props = [];
26 protected $reviewers = [];
27
34 public function __construct( $key, $definition ) {
35 $this->key = $key;
36 $this->definition = $definition;
37 }
38
43 public function key() {
44 return $this->key;
45 }
46
51 public function definition() {
52 return $this->definition;
53 }
54
59 abstract public function translation();
60
65 public function setInfile( $text ) {
66 $this->infile = $text;
67 }
68
73 public function infile() {
74 return $this->infile;
75 }
76
81 public function addTag( $tag ) {
82 $this->tags[] = $tag;
83 }
84
90 public function hasTag( $tag ) {
91 return in_array( $tag, $this->tags, true );
92 }
93
98 public function getTags() {
99 return $this->tags;
100 }
101
102 public function setProperty( $key, $value ) {
103 $this->props[$key] = $value;
104 }
105
106 public function appendProperty( $key, $value ) {
107 if ( !isset( $this->props[$key] ) ) {
108 $this->props[$key] = [];
109 }
110 $this->props[$key][] = $value;
111 }
112
113 public function getProperty( $key ) {
114 return $this->props[$key] ?? null;
115 }
116
122 public function getPropertyNames() {
123 return array_keys( $this->props );
124 }
125}
126
132class ThinMessage extends TMessage {
133 // This maps properties to fields in the database result row
134 protected static $propertyMap = [
135 'last-translator-text' => 'rev_user_text',
136 'last-translator-id' => 'rev_user',
137 ];
139 protected $row;
141 protected $translation;
142
147 public function setRow( $row ) {
148 $this->row = $row;
149 }
150
155 public function setTranslation( $text ) {
156 $this->translation = $text;
157 }
158
160 public function translation() {
161 if ( !isset( $this->row ) ) {
162 return $this->infile();
163 }
164
165 return $this->translation;
166 }
167
168 // Re-implemented
169 public function getProperty( $key ) {
170 if ( !isset( self::$propertyMap[$key] ) ) {
171 return parent::getProperty( $key );
172 }
173
174 $field = self::$propertyMap[$key];
175
176 return $this->row->$field ?? null;
177 }
178
179 // Re-implemented
180 public function getPropertyNames() {
181 return array_merge( parent::getPropertyNames(), array_keys( self::$propertyMap ) );
182 }
183}
184
189class FatMessage extends TMessage {
191 protected $translation;
192
197 public function setTranslation( $text ) {
198 $this->translation = $text;
199 }
200
201 public function translation() {
202 if ( $this->translation === null ) {
203 return $this->infile;
204 }
205
206 return $this->translation;
207 }
208}
Message object where you can directly set the translation.
Definition Message.php:189
translation()
Get the message translation.
Definition Message.php:201
setTranslation( $text)
Set the current translation of this message.
Definition Message.php:197
Interface for message objects used by MessageCollection.
Definition Message.php:14
definition()
Get the message definition.
Definition Message.php:51
hasTag( $tag)
Check if this message has a given tag.
Definition Message.php:90
addTag( $tag)
Add a tag for this message.
Definition Message.php:81
translation()
Get the message translation.
key()
Get the message key.
Definition Message.php:43
getPropertyNames()
Get all the available property names.
Definition Message.php:122
__construct( $key, $definition)
Creates new message object.
Definition Message.php:34
getTags()
Return all tags for this message;.
Definition Message.php:98
infile()
Returns the committed translation.
Definition Message.php:73
setInfile( $text)
Set the committed translation.
Definition Message.php:65
Message object which is based on database result row.
Definition Message.php:132
getPropertyNames()
Get all the available property names.
Definition Message.php:180
translation()
@inheritDoc
Definition Message.php:160
setTranslation( $text)
Set the current translation of this message.
Definition Message.php:155
setRow( $row)
Set the database row this message is based on.
Definition Message.php:147