MediaWiki 1.43.1
TextFormatter.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Message;
4
7
11class TextFormatter implements ITextFormatter {
13 private $langCode;
14
16 private $format;
17
29 public function __construct(
30 string $langCode,
31 string $format = Message::FORMAT_TEXT
32 ) {
33 $this->langCode = $langCode;
34 $this->format = $format;
35 }
36
37 public function getLangCode() {
38 return $this->langCode;
39 }
40
49 protected function createMessage( MessageSpecifier $spec ) {
50 return Message::newFromSpecifier( $spec );
51 }
52
53 public function format( MessageSpecifier $mv ): string {
54 $message = $this->createMessage( $mv );
55 $message->inLanguage( $this->langCode );
56 return $message->toString( $this->format );
57 }
58}
static newFromSpecifier( $value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...
Definition Message.php:471
const FORMAT_TEXT
Transform {{..}} constructs but don't transform to HTML.
Definition Message.php:164
The MediaWiki-specific implementation of ITextFormatter.
createMessage(MessageSpecifier $spec)
Allow the Message class to be mocked in tests by constructing objects in a protected method.
format(MessageSpecifier $mv)
Convert a MessageSpecifier to text.
getLangCode()
Get the internal language code in which format() is.
__construct(string $langCode, string $format=Message::FORMAT_TEXT)
Construct a TextFormatter.