Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ReferenceMessageLocalizer | |
100.00% |
4 / 4 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
localizeSeparators | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
localizeDigits | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
msg | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Cite; |
4 | |
5 | use MediaWiki\Language\Language; |
6 | use MediaWiki\Message\Message; |
7 | use MessageLocalizer; |
8 | use Wikimedia\Message\MessageSpecifier; |
9 | |
10 | /** |
11 | * Interface abstracts everything a Cite needs to do with languages. |
12 | * |
13 | * @license GPL-2.0-or-later |
14 | */ |
15 | class ReferenceMessageLocalizer implements MessageLocalizer { |
16 | |
17 | private Language $language; |
18 | |
19 | public function __construct( Language $language ) { |
20 | $this->language = $language; |
21 | } |
22 | |
23 | public function localizeSeparators( string $number ): string { |
24 | // Filter to make sure characters are never removed |
25 | return strtr( $number, array_filter( $this->language->separatorTransformTable() ?: [] ) ); |
26 | } |
27 | |
28 | /** |
29 | * Transliterate numerals, without adding or changing separators. |
30 | */ |
31 | public function localizeDigits( string $number ): string { |
32 | return $this->language->formatNumNoSeparators( $number ); |
33 | } |
34 | |
35 | /** |
36 | * This is the method for getting translated interface messages. |
37 | * |
38 | * Note that it returns messages coerced to a specific language, the content language |
39 | * rather than the UI language. |
40 | * |
41 | * @see https://www.mediawiki.org/wiki/Manual:Messages_API |
42 | * @see Message::__construct |
43 | * |
44 | * @param string|string[]|MessageSpecifier $key Message key, or array of keys, |
45 | * or a MessageSpecifier. |
46 | * @param mixed ...$params Normal message parameters |
47 | * |
48 | * @return Message |
49 | */ |
50 | public function msg( $key, ...$params ): Message { |
51 | return wfMessage( $key, ...$params )->inLanguage( $this->language ); |
52 | } |
53 | |
54 | } |