aboutsummaryrefslogtreecommitdiffstats
path: root/includes/language/Message/MessageFormatterFactory.php
blob: b15e5df1650b37f2c4525e8467852055d49f6db5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php

namespace MediaWiki\Message;

use Wikimedia\Message\IMessageFormatterFactory;
use Wikimedia\Message\ITextFormatter;

/**
 * The MediaWiki-specific implementation of IMessageFormatterFactory
 *
 * To obtain an instance, use \MediaWiki\MediaWikiServices::getMessageFormatterFactory().
 *
 * @ingroup Language
 */
class MessageFormatterFactory implements IMessageFormatterFactory {
	private string $format;
	private array $textFormatters = [];

	/**
	 * @internal For use by ServiceWiring only
	 * @param string $format which if the Message::FORMAT_* to use in the formatters.
	 */
	public function __construct( string $format = Message::FORMAT_TEXT ) {
		$this->format = $format;
	}

	/**
	 * @inheritDoc
	 */
	public function getTextFormatter( string $langCode ): ITextFormatter {
		if ( !isset( $this->textFormatters[$langCode] ) ) {
			$this->textFormatters[$langCode] = new TextFormatter(
				$langCode, $this->format );
		}
		return $this->textFormatters[$langCode];
	}
}