Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| SimpleLocalizationContext | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLanguageCode | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| msg | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Language; |
| 8 | |
| 9 | use Wikimedia\Bcp47Code\Bcp47Code; |
| 10 | |
| 11 | /** |
| 12 | * An implementation of {@link LocalizationContext} that implements only the methods defined in the interface. |
| 13 | * |
| 14 | * Intended for use where you don't have access to a {@link LocalizationContext} but have access to a |
| 15 | * {@link Bcp47Code} and {@link MessageLocalizer}. |
| 16 | * |
| 17 | * Callers should usually ensure the languages are the same for the {@link Bcp47Code} and |
| 18 | * the {@link MessageLocalizer}. |
| 19 | * |
| 20 | * @newable |
| 21 | * @since 1.47 |
| 22 | * @ingroup Language |
| 23 | */ |
| 24 | class SimpleLocalizationContext implements LocalizationContext { |
| 25 | |
| 26 | public function __construct( |
| 27 | private readonly MessageLocalizer $messageLocalizer, |
| 28 | private readonly Bcp47Code $language, |
| 29 | ) { |
| 30 | } |
| 31 | |
| 32 | /** @inheritDoc */ |
| 33 | public function getLanguageCode() { |
| 34 | return $this->language; |
| 35 | } |
| 36 | |
| 37 | /** @inheritDoc */ |
| 38 | public function msg( $key, ...$params ) { |
| 39 | return $this->messageLocalizer->msg( $key, ...$params ); |
| 40 | } |
| 41 | } |