2019-12-03 23:39:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite;
|
|
|
|
|
|
|
|
use Language;
|
|
|
|
use Message;
|
|
|
|
use MessageLocalizer;
|
|
|
|
use MessageSpecifier;
|
|
|
|
|
2019-12-04 16:54:35 +00:00
|
|
|
/**
|
|
|
|
* Interface abstracts everything a Cite needs to do with languages.
|
|
|
|
*/
|
2019-12-03 23:39:28 +00:00
|
|
|
class ReferenceMessageLocalizer implements MessageLocalizer {
|
|
|
|
/**
|
|
|
|
* @var Language
|
|
|
|
*/
|
|
|
|
private $language;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Language $language
|
|
|
|
*/
|
|
|
|
public function __construct( Language $language ) {
|
|
|
|
$this->language = $language;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-12-06 09:12:25 +00:00
|
|
|
* Transliterate numerals, add thousands separators and localize the decimal point.
|
|
|
|
*
|
|
|
|
* @param string $number
|
|
|
|
* @return string
|
2019-12-03 23:39:28 +00:00
|
|
|
*/
|
2019-12-06 09:12:25 +00:00
|
|
|
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 formatNumNoSeparators( string $number ): string {
|
|
|
|
return $this->language->formatNumNoSeparators( $number );
|
2019-12-03 23:39:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the method for getting translated interface messages.
|
|
|
|
*
|
2019-12-04 16:54:35 +00:00
|
|
|
* Note that it returns messages coerced to a specific language, the content language
|
|
|
|
* rather than the UI language.
|
|
|
|
*
|
2019-12-03 23:39:28 +00:00
|
|
|
* @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 );
|
|
|
|
}
|
2019-12-06 09:12:25 +00:00
|
|
|
|
2019-12-03 23:39:28 +00:00
|
|
|
}
|