Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / mocks / MockMessageLocalizer.php
blob6c0b955f90a3b33614b1460d779fdd34a4802768
1 <?php
3 use MediaWiki\Message\Message;
4 use Wikimedia\Message\MessageSpecifier;
6 /**
7 * A simple {@link MessageLocalizer} implementation for use in tests.
8 * By default, it sets the message language to 'qqx',
9 * to make the tests independent of the wiki configuration.
11 * @author Lucas Werkmeister
12 * @license GPL-2.0-or-later
14 class MockMessageLocalizer implements MessageLocalizer {
16 /**
17 * @var string|null
19 private $languageCode;
21 /**
22 * @param string|null $languageCode The language code to use for messages by default.
23 * You can specify null to use the user language,
24 * but this is not recommended as it may make your tests depend on the wiki configuration.
26 public function __construct( $languageCode = 'qqx' ) {
27 $this->languageCode = $languageCode;
30 /**
31 * Get a Message object.
32 * Parameters are the same as {@link wfMessage()}.
34 * @param string|string[]|MessageSpecifier $key Message key, or array of keys,
35 * or a MessageSpecifier.
36 * @phpcs:ignore Generic.Files.LineLength
37 * @param MessageParam|MessageSpecifier|string|int|float|list<MessageParam|MessageSpecifier|string|int|float> ...$params
38 * See Message::params()
39 * @return Message
41 public function msg( $key, ...$params ) {
42 $message = wfMessage( $key, ...$params );
44 if ( $this->languageCode !== null ) {
45 $message->inLanguage( $this->languageCode );
48 return $message;