Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
LexemeLanguageNameLookup | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getName | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikibase\Lexeme\MediaWiki\Content; |
4 | |
5 | use MessageLocalizer; |
6 | use Wikibase\Lib\LanguageNameLookup; |
7 | |
8 | /** |
9 | * @license GPL-2.0-or-later |
10 | */ |
11 | class LexemeLanguageNameLookup { |
12 | |
13 | /** |
14 | * @var MessageLocalizer |
15 | */ |
16 | private $messageLocalizer; |
17 | |
18 | /** |
19 | * @var string[] |
20 | */ |
21 | private $additionalLanguageCodes; |
22 | |
23 | /** |
24 | * @var LanguageNameLookup |
25 | */ |
26 | private $fallbackLookup; |
27 | |
28 | public function __construct( |
29 | MessageLocalizer $messageLocalizer, |
30 | array $additionalLanguageCodes, |
31 | LanguageNameLookup $fallbackLookup |
32 | ) { |
33 | $this->messageLocalizer = $messageLocalizer; |
34 | $this->additionalLanguageCodes = $additionalLanguageCodes; |
35 | $this->fallbackLookup = $fallbackLookup; |
36 | } |
37 | |
38 | /** |
39 | * @param string $languageCode |
40 | * |
41 | * @return string |
42 | */ |
43 | public function getName( $languageCode ) { |
44 | if ( in_array( $languageCode, $this->additionalLanguageCodes ) ) { |
45 | return $this->messageLocalizer |
46 | ->msg( 'wikibase-lexeme-language-name-' . $languageCode ) |
47 | ->plain(); |
48 | } |
49 | |
50 | return $this->fallbackLookup->getName( $languageCode ); |
51 | } |
52 | |
53 | } |