Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
MediaWikiLocalization | |
0.00% |
0 / 3 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
msg | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * MediaWikiLocalization.php |
4 | * |
5 | * This file is part of the Codex design system, the official design system |
6 | * for Wikimedia projects. It defines the `MediaWikiLocalization` class, which |
7 | * provides localized messages using the MediaWiki `RequestContext` message system. |
8 | * |
9 | * The `MediaWikiLocalization` class allows Codex components to retrieve |
10 | * translated messages in environments where MediaWiki is available. This ensures |
11 | * that the localization method is consistent and flexible within the Codex system. |
12 | * |
13 | * @category Localization |
14 | * @package Codex\Localization |
15 | * @since 0.1.0 |
16 | * @author Doğu Abaris <abaris@null.net> |
17 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
18 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
19 | */ |
20 | |
21 | namespace Wikimedia\Codex\Localization; |
22 | |
23 | use MediaWiki\Context\RequestContext; |
24 | use Wikimedia\Codex\Contract\ILocalizer; |
25 | |
26 | /** |
27 | * Localization class for MediaWiki environment. |
28 | * |
29 | * The `MediaWikiLocalization` class uses the MediaWiki `RequestContext` to retrieve |
30 | * localized messages based on a message key and optional parameters. By implementing |
31 | * the `ILocalizer` interface, this class ensures consistent access to localized messages |
32 | * for Codex components within a MediaWiki environment. |
33 | * |
34 | * @category Localization |
35 | * @package Codex\Localization |
36 | * @since 0.1.0 |
37 | * @author Doğu Abaris <abaris@null.net> |
38 | * @license https://www.gnu.org/copyleft/gpl.html GPL-2.0-or-later |
39 | * @link https://doc.wikimedia.org/codex/main/ Codex Documentation |
40 | */ |
41 | class MediaWikiLocalization implements ILocalizer { |
42 | |
43 | /** |
44 | * The request context from which localized messages are retrieved. |
45 | */ |
46 | private RequestContext $context; |
47 | |
48 | /** |
49 | * Constructor for the MediaWikiLocalization class. |
50 | * |
51 | * @param RequestContext $context The MediaWiki request context. |
52 | */ |
53 | public function __construct( RequestContext $context ) { |
54 | $this->context = $context; |
55 | } |
56 | |
57 | /** |
58 | * Retrieve a localized message using MediaWiki’s RequestContext. |
59 | * |
60 | * This method fetches a translated message from MediaWiki using the provided message key |
61 | * and optional parameters. The message key identifies the message, while the parameters |
62 | * allow dynamic values to be inserted into the message. |
63 | * |
64 | * @param string $key The message key. |
65 | * @param array $params Parameters for message replacements. |
66 | * @return string The localized message. |
67 | */ |
68 | public function msg( string $key, array $params = [] ): string { |
69 | return $this->context->msg( $key, ...$params )->text(); |
70 | } |
71 | } |