Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
I18nInfo | |
0.00% |
0 / 6 |
|
0.00% |
0 / 4 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
createInterfaceI18n | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createPageContentI18n | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
createLangI18n | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\NodeData; |
5 | |
6 | use Wikimedia\Bcp47Code\Bcp47Code; |
7 | |
8 | class I18nInfo { |
9 | public const USER_LANG = "x-user"; |
10 | public const PAGE_LANG = "x-page"; |
11 | |
12 | /** |
13 | * Value for the "lang" parameter. Can be one of USER_LANG or PAGE_LANG, or a fixed language |
14 | * code (discouraged when USER_LANG or PAGE_LANG could be used instead). |
15 | * @var string |
16 | */ |
17 | public $lang; |
18 | |
19 | /** |
20 | * Key of the message in localization files |
21 | * @var string |
22 | */ |
23 | public $key; |
24 | |
25 | /** |
26 | * Ordered list of parameters for the localized message |
27 | * @var ?array |
28 | */ |
29 | public $params; |
30 | |
31 | public function __construct( string $lang, string $key, ?array $params = null ) { |
32 | $this->lang = $lang; |
33 | $this->key = $key; |
34 | $this->params = $params; |
35 | } |
36 | |
37 | /** |
38 | * Creates internationalization information for a string or attribute value in the user |
39 | * interface language. |
40 | * @param string $key |
41 | * @param array|null $params |
42 | * @return I18nInfo |
43 | */ |
44 | public static function createInterfaceI18n( string $key, ?array $params ): I18nInfo { |
45 | return new I18nInfo( self::USER_LANG, $key, $params ); |
46 | } |
47 | |
48 | /** |
49 | * Creates internationalization information for a string or attribute value in the page |
50 | * content language. |
51 | * @param string $key |
52 | * @param array|null $params |
53 | * @return I18nInfo |
54 | */ |
55 | public static function createPageContentI18n( string $key, ?array $params ): I18nInfo { |
56 | return new I18nInfo( self::PAGE_LANG, $key, $params ); |
57 | } |
58 | |
59 | /** |
60 | * Creates internationalization information for a string or attribute value in an arbitrary |
61 | * language. |
62 | * The use of this method is discouraged; use ::createPageContentI18n(...) and |
63 | * ::createInterfaceI18n(...) where possible rather than, respectively, |
64 | * ::createLangI18n($wgContLang, ...) and ::createLangI18n($wgLang, ...). |
65 | * @param Bcp47Code $lang |
66 | * @param string $key |
67 | * @param array|null $params |
68 | * @return I18nInfo |
69 | */ |
70 | public static function createLangI18n( Bcp47Code $lang, string $key, ?array $params ): I18nInfo { |
71 | return new I18nInfo( $lang->toBcp47Code(), $key, $params ); |
72 | } |
73 | } |