Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
MediaWikiLocalization
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 msg
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4/**
5 * MediaWikiLocalization.php
6 *
7 * This file is part of the Codex design system, the official design system
8 * for Wikimedia projects. It defines the `MediaWikiLocalization` class, which
9 * provides localized messages using the MediaWiki `RequestContext` message system.
10 *
11 * The `MediaWikiLocalization` class allows Codex components to retrieve
12 * translated messages in environments where MediaWiki is available. This ensures
13 * that the localization method is consistent and flexible within the Codex system.
14 *
15 * @category Localization
16 * @package  Codex\Localization
17 * @since    0.1.0
18 * @author   Doğu Abaris <abaris@null.net>
19 * @license  https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later
20 * @link     https://doc.wikimedia.org/codex/main/ Codex Documentation
21 */
22
23namespace Wikimedia\Codex\Localization;
24
25use MediaWiki\Language\MessageLocalizer;
26use Wikimedia\Codex\Contract\ILocalizer;
27
28/**
29 * Localization class for MediaWiki environment.
30 *
31 * The `MediaWikiLocalization` class uses a MediaWiki `MessageLocalizer` to retrieve
32 * localized messages based on a message key and optional parameters. By implementing
33 * the `ILocalizer` interface, this class ensures consistent access to localized messages
34 * for Codex components within a MediaWiki environment.
35 *
36 * @category Localization
37 * @package  Codex\Localization
38 * @since    0.1.0
39 * @author   Doğu Abaris <abaris@null.net>
40 * @license  https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later
41 * @link     https://doc.wikimedia.org/codex/main/ Codex Documentation
42 */
43class MediaWikiLocalization implements ILocalizer {
44
45    public function __construct(
46        private readonly MessageLocalizer $messageLocalizer
47    ) {
48    }
49
50    /** @inheritDoc */
51    public function msg( string $key, ...$params ): string {
52        return $this->messageLocalizer->msg( $key, ...$params )->text();
53    }
54}