3 use MediaWiki\Message\Message
;
4 use Wikimedia\Message\MessageSpecifier
;
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
{
19 private $languageCode;
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;
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()
41 public function msg( $key, ...$params ) {
42 $message = wfMessage( $key, ...$params );
44 if ( $this->languageCode
!== null ) {
45 $message->inLanguage( $this->languageCode
);