Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
IntuitionLocalization | |
0.00% |
0 / 2 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
msg | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * IntuitionLocalization.php |
4 | * |
5 | * This file is part of the Codex design system, the official design system |
6 | * for Wikimedia projects. It defines the `IntuitionLocalization` class, which |
7 | * provides localized messages using the Intuition library for non-MediaWiki environments. |
8 | * |
9 | * The `IntuitionLocalization` class allows Codex components to retrieve translated messages |
10 | * in non-MediaWiki environments, ensuring consistency and flexibility in localization |
11 | * within the Codex system, regardless of the platform. |
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 Krinkle\Intuition\Intuition; |
24 | use Wikimedia\Codex\Contract\ILocalizer; |
25 | |
26 | /** |
27 | * Localization class for non-MediaWiki environments using Intuition. |
28 | * |
29 | * The `IntuitionLocalization` class uses the Intuition library to retrieve localized |
30 | * messages for Codex components in non-MediaWiki environments. By implementing |
31 | * the `ILocalizer` interface, this class ensures Codex components |
32 | * have consistent access to localized messages across different environments. |
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 IntuitionLocalization implements ILocalizer { |
42 | |
43 | /** |
44 | * Instance of the Intuition library used for retrieving localized messages. |
45 | * |
46 | * This instance provides access to the Intuition message localization system, |
47 | * which enables localized messages to be fetched based on a message key and |
48 | * optional parameters. |
49 | */ |
50 | private Intuition $localizer; |
51 | |
52 | /** |
53 | * Constructor with dependency injection for Intuition. |
54 | * |
55 | * @param Intuition $localizer The Intuition instance. |
56 | */ |
57 | public function __construct( Intuition $localizer ) { |
58 | $this->localizer = $localizer; |
59 | } |
60 | |
61 | /** |
62 | * Retrieve a localized message using Intuition. |
63 | * |
64 | * This method fetches a translated message from the Intuition library based on |
65 | * the provided message key and optional parameters. The message key identifies |
66 | * the message, while the parameters allow dynamic values to be inserted into the message. |
67 | * |
68 | * @param string $key The message key. |
69 | * @param array $params Parameters for message replacements. |
70 | * @return string The localized message. |
71 | */ |
72 | public function msg( string $key, array $params = [] ): string { |
73 | return $this->localizer->msg( $key, $params ); |
74 | } |
75 | } |