The Action API is going to need to convert between the two at various boundaries where it receives a Status from business logic. Also when we make HtmlFormatter and the like, that'll initially need the same conversion logic too. Change-Id: Id5b216b033718f3ef38bfd4be1715218ee07bb93
43 lines
992 B
PHP
43 lines
992 B
PHP
<?php
|
|
|
|
namespace MediaWiki\Message;
|
|
|
|
use Wikimedia\Message\ITextFormatter;
|
|
use Wikimedia\Message\MessageValue;
|
|
|
|
/**
|
|
* The MediaWiki-specific implementation of ITextFormatter
|
|
*/
|
|
class TextFormatter implements ITextFormatter {
|
|
/** @var Converter */
|
|
private $converter;
|
|
|
|
/** @var string */
|
|
private $langCode;
|
|
|
|
/**
|
|
* Construct a TextFormatter.
|
|
*
|
|
* The type signature may change without notice as dependencies are added
|
|
* to the constructor. External callers should use
|
|
* MediaWikiServices::getMessageFormatterFactory()
|
|
*
|
|
* @internal
|
|
* @param string $langCode
|
|
* @param Converter $converter
|
|
*/
|
|
public function __construct( $langCode, Converter $converter ) {
|
|
$this->langCode = $langCode;
|
|
$this->converter = $converter;
|
|
}
|
|
|
|
public function getLangCode() {
|
|
return $this->langCode;
|
|
}
|
|
|
|
public function format( MessageValue $mv ) {
|
|
$message = $this->converter->convertMessageValue( $mv );
|
|
$message->inLanguage( $this->langCode );
|
|
return $message->text();
|
|
}
|
|
}
|