2019-12-03 23:39:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Cite;
|
|
|
|
|
2024-10-19 21:25:16 +00:00
|
|
|
use MediaWiki\Language\Language;
|
2024-06-08 21:31:42 +00:00
|
|
|
use MediaWiki\Message\Message;
|
2019-12-03 23:39:28 +00:00
|
|
|
use MessageLocalizer;
|
2024-10-19 21:25:16 +00:00
|
|
|
use Wikimedia\Message\MessageSpecifier;
|
2019-12-03 23:39:28 +00:00
|
|
|
|
2019-12-04 16:54:35 +00:00
|
|
|
/**
|
|
|
|
* Interface abstracts everything a Cite needs to do with languages.
|
2023-12-15 11:12:16 +00:00
|
|
|
*
|
|
|
|
* @license GPL-2.0-or-later
|
2019-12-04 16:54:35 +00:00
|
|
|
*/
|
2019-12-03 23:39:28 +00:00
|
|
|
class ReferenceMessageLocalizer implements MessageLocalizer {
|
2019-12-10 15:21:12 +00:00
|
|
|
|
2023-06-05 14:36:03 +00:00
|
|
|
private Language $language;
|
2019-12-03 23:39:28 +00:00
|
|
|
|
|
|
|
public function __construct( Language $language ) {
|
|
|
|
$this->language = $language;
|
|
|
|
}
|
|
|
|
|
2021-07-22 05:44:15 +00:00
|
|
|
public function localizeSeparators( string $number ): string {
|
2020-09-02 07:40:33 +00:00
|
|
|
// Filter to make sure characters are never removed
|
|
|
|
return strtr( $number, array_filter( $this->language->separatorTransformTable() ?: [] ) );
|
2019-12-06 09:12:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transliterate numerals, without adding or changing separators.
|
|
|
|
*/
|
2021-07-22 05:44:15 +00:00
|
|
|
public function localizeDigits( string $number ): string {
|
2019-12-06 09:12:25 +00:00
|
|
|
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
|
2019-12-10 15:21:12 +00:00
|
|
|
*
|
2019-12-03 23:39:28 +00:00
|
|
|
* @return Message
|
|
|
|
*/
|
2021-07-22 05:44:15 +00:00
|
|
|
public function msg( $key, ...$params ): Message {
|
2019-12-03 23:39:28 +00:00
|
|
|
return wfMessage( $key, ...$params )->inLanguage( $this->language );
|
|
|
|
}
|
2019-12-06 09:12:25 +00:00
|
|
|
|
2019-12-03 23:39:28 +00:00
|
|
|
}
|