mediawiki-extensions-Cite/src/ReferenceMessageLocalizer.php
Thiemo Kreuz 013e1bfa90 Final clean-ups for a more consistent parameter order
* Always have an empty line between @param and @return to improve
readability as well as consistency within this codebase (before, both
styles have been used).

* Flip parameter order in validateRefInReferences() for consistency with
the rest of the code.

* In Cite::guardedRef() the Parser was now the 1st parameter. I changed
all related functions the same way to make the code less surprising.

* Same in CiteUnitTest. This is really just the @dataProvider. But I feel
it's still helpful to have the arguments in the same order everywhere, if
possible.

* Add a few strict type hints.

* It seems the preferred style for PHP7 return types is `… ) : string {`
with a space before the `:`. There is currently no PHPCS sniff for this.
However, I think this codebase should be consistent, one way or the other.

Change-Id: I91d232be727afd26ff20526ab4ef63aa5ba6bacf
2020-01-09 12:13:54 +01:00

69 lines
1.5 KiB
PHP

<?php
namespace Cite;
use Language;
use Message;
use MessageLocalizer;
use MessageSpecifier;
/**
* Interface abstracts everything a Cite needs to do with languages.
*/
class ReferenceMessageLocalizer implements MessageLocalizer {
/**
* @var Language
*/
private $language;
/**
* @param Language $language
*/
public function __construct( Language $language ) {
$this->language = $language;
}
/**
* Transliterate numerals, add thousands separators and localize the decimal point.
*
* @param string $number
*
* @return string
*/
public function formatNum( string $number ) : string {
return $this->language->formatNum( $number );
}
/**
* Transliterate numerals, without adding or changing separators.
*
* @param string $number
*
* @return string
*/
public function localizeDigits( string $number ) : string {
return $this->language->formatNumNoSeparators( $number );
}
/**
* This is the method for getting translated interface messages.
*
* Note that it returns messages coerced to a specific language, the content language
* rather than the UI language.
*
* @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 );
}
}