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