mediawiki-extensions-Cite/src/ReferenceMessageLocalizer.php
Adam Wight 3d80501829 Narrow message localizer interface
We never access Language directly, so proxy its method instead of
returning the full object.

I believe I've found a bug, but not fixing here: the footnote body
numeric backlinks like "2.1" behave as if they were decimals rather
than two numbers stuck together with a dot.  So they are localized
to "2,1".

Bug: T239725
Change-Id: If386bf96d48cb95c0a287a02bedfe984941efe30
2019-12-06 12:17:09 +01:00

65 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 formatNumNoSeparators( 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 );
}
}