MediaWiki  master
TextFormatter.php
Go to the documentation of this file.
1 <?php
2 
3 namespace MediaWiki\Message;
4 
5 use Message;
8 
12 class TextFormatter implements ITextFormatter {
14  private $converter;
15 
17  private $langCode;
18 
20  private $format;
21 
34  public function __construct(
35  string $langCode,
36  Converter $converter,
37  string $format = Message::FORMAT_TEXT
38  ) {
39  $this->langCode = $langCode;
40  $this->converter = $converter;
41  $this->format = $format;
42  }
43 
44  public function getLangCode() {
45  return $this->langCode;
46  }
47 
48  public function format( MessageValue $mv ) {
49  $message = $this->converter->convertMessageValue( $mv );
50  $message->inLanguage( $this->langCode );
51  return $message->toString( $this->format );
52  }
53 }
Converter between Message and MessageValue.
Definition: Converter.php:18
The MediaWiki-specific implementation of ITextFormatter.
getLangCode()
Get the internal language code in which format() is.
format(MessageValue $mv)
__construct(string $langCode, Converter $converter, string $format=Message::FORMAT_TEXT)
Construct a TextFormatter.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition: Message.php:144
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
Definition: Message.php:152
string null false $message
Definition: Message.php:216
Value object representing a message for i18n.