mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-24 06:54:00 +00:00
Introduce ReferenceMessageLocalizer
Encapsulate the language interfaces, this will be used to replace global wfMessage calls in future patches. Change-Id: I7857f3e5154626e0b29977610b81103d91615f65
This commit is contained in:
parent
0f146cd56e
commit
bccb92335f
46
src/ReferenceMessageLocalizer.php
Normal file
46
src/ReferenceMessageLocalizer.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Cite;
|
||||
|
||||
use Language;
|
||||
use Message;
|
||||
use MessageLocalizer;
|
||||
use MessageSpecifier;
|
||||
|
||||
class ReferenceMessageLocalizer implements MessageLocalizer {
|
||||
|
||||
/**
|
||||
* @var Language
|
||||
*/
|
||||
private $language;
|
||||
|
||||
/**
|
||||
* @param Language $language
|
||||
*/
|
||||
public function __construct( Language $language ) {
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Language
|
||||
*/
|
||||
public function getLanguage(): Language {
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the method for getting translated interface messages.
|
||||
*
|
||||
* @see https://www.mediawiki.org/wiki/Manual:Messages_API
|
||||
* @see Message::__construct
|
||||
*
|
||||
* @param string|string[]|MessageSpecifier $key Message key, or array of keys,
|
||||
* or a MessageSpecifier.
|
||||
* @param mixed ...$params Normal message parameters
|
||||
* @return Message
|
||||
*/
|
||||
public function msg( $key, ...$params ): Message {
|
||||
return wfMessage( $key, ...$params )->inLanguage( $this->language );
|
||||
}
|
||||
|
||||
}
|
21
tests/phpunit/ReferenceMessageLocalizerTest.php
Normal file
21
tests/phpunit/ReferenceMessageLocalizerTest.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Cite;
|
||||
|
||||
use LanguageQqx;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Cite\ReferenceMessageLocalizer
|
||||
*/
|
||||
class ReferenceMessageLocalizerTest extends MediaWikiIntegrationTestCase {
|
||||
/**
|
||||
* @covers ::msg
|
||||
*/
|
||||
public function testMsg() {
|
||||
$localizer = new ReferenceMessageLocalizer( new LanguageQqx() );
|
||||
$this->assertSame(
|
||||
'(cite_reference_link_prefix)',
|
||||
$localizer->msg( 'cite_reference_link_prefix' )->plain() );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue