Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
188 / 188 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| LanguageService | |
100.00% |
188 / 188 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
187 / 187 |
|
100.00% |
1 / 1 |
1 | |||
| getLanguageLabel | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Drupal\visitors\Service; |
| 4 | |
| 5 | use Drupal\Component\Render\MarkupInterface; |
| 6 | use Drupal\Core\StringTranslation\StringTranslationTrait; |
| 7 | use Drupal\Core\StringTranslation\TranslationInterface; |
| 8 | use Drupal\visitors\VisitorsLanguageInterface; |
| 9 | |
| 10 | /** |
| 11 | * The language service. |
| 12 | */ |
| 13 | class LanguageService implements VisitorsLanguageInterface { |
| 14 | use StringTranslationTrait; |
| 15 | |
| 16 | /** |
| 17 | * List of languages. |
| 18 | * |
| 19 | * @var array |
| 20 | */ |
| 21 | protected $languages = []; |
| 22 | |
| 23 | /** |
| 24 | * Constructs a new LanguageService object. |
| 25 | * |
| 26 | * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation |
| 27 | * The string translation service. |
| 28 | */ |
| 29 | public function __construct(TranslationInterface $string_translation) { |
| 30 | |
| 31 | $this->setStringTranslation($string_translation); |
| 32 | |
| 33 | $this->languages = [ |
| 34 | 'ab' => $this->t('Abkhaz'), |
| 35 | 'aa' => $this->t('Afar'), |
| 36 | 'af' => $this->t('Afrikaans'), |
| 37 | 'ak' => $this->t('Akan'), |
| 38 | 'sq' => $this->t('Albanian'), |
| 39 | 'am' => $this->t('Amharic'), |
| 40 | 'ar' => $this->t('Arabic'), |
| 41 | 'an' => $this->t('Aragonese'), |
| 42 | 'hy' => $this->t('Armenian'), |
| 43 | 'as' => $this->t('Assamese'), |
| 44 | 'av' => $this->t('Avaric'), |
| 45 | 'ae' => $this->t('Avestan'), |
| 46 | 'ay' => $this->t('Aymara'), |
| 47 | 'az' => $this->t('Azerbaijani'), |
| 48 | 'bm' => $this->t('Bambara'), |
| 49 | 'ba' => $this->t('Bashkir'), |
| 50 | 'eu' => $this->t('Basque'), |
| 51 | 'be' => $this->t('Belarusian'), |
| 52 | 'bn' => $this->t('Bengali'), |
| 53 | 'bh' => $this->t('Bihari'), |
| 54 | 'bi' => $this->t('Bislama'), |
| 55 | 'bs' => $this->t('Bosnian'), |
| 56 | 'br' => $this->t('Breton'), |
| 57 | 'bg' => $this->t('Bulgarian'), |
| 58 | 'my' => $this->t('Burmese'), |
| 59 | 'ca' => $this->t('Catalan'), |
| 60 | 'ch' => $this->t('Chamorro'), |
| 61 | 'ce' => $this->t('Chechen'), |
| 62 | 'ny' => $this->t('Chichewa'), |
| 63 | 'zh' => $this->t('Chinese'), |
| 64 | 'cv' => $this->t('Chuvash'), |
| 65 | 'kw' => $this->t('Cornish'), |
| 66 | 'co' => $this->t('Corsican'), |
| 67 | 'cr' => $this->t('Cree'), |
| 68 | 'hr' => $this->t('Croatian'), |
| 69 | 'cs' => $this->t('Czech'), |
| 70 | 'da' => $this->t('Danish'), |
| 71 | 'dv' => $this->t('Divehi'), |
| 72 | 'nl' => $this->t('Dutch'), |
| 73 | 'dz' => $this->t('Dzongkha'), |
| 74 | 'en' => $this->t('English'), |
| 75 | 'eo' => $this->t('Esperanto'), |
| 76 | 'et' => $this->t('Estonian'), |
| 77 | 'ee' => $this->t('Ewe'), |
| 78 | 'fo' => $this->t('Faroese'), |
| 79 | 'fj' => $this->t('Fijian'), |
| 80 | 'fi' => $this->t('Finnish'), |
| 81 | 'fr' => $this->t('French'), |
| 82 | 'ff' => $this->t('Fula'), |
| 83 | 'gl' => $this->t('Galician'), |
| 84 | 'ka' => $this->t('Georgian'), |
| 85 | 'de' => $this->t('German'), |
| 86 | 'el' => $this->t('Greek (modern)'), |
| 87 | 'gn' => $this->t('Guaraní'), |
| 88 | 'gu' => $this->t('Gujarati'), |
| 89 | 'ht' => $this->t('Haitian'), |
| 90 | 'ha' => $this->t('Hausa'), |
| 91 | 'he' => $this->t('Hebrew (modern)'), |
| 92 | 'hz' => $this->t('Herero'), |
| 93 | 'hi' => $this->t('Hindi'), |
| 94 | 'ho' => $this->t('Hiri Motu'), |
| 95 | 'hu' => $this->t('Hungarian'), |
| 96 | 'ia' => $this->t('Interlingua'), |
| 97 | 'id' => $this->t('Indonesian'), |
| 98 | 'ie' => $this->t('Interlingue'), |
| 99 | 'ga' => $this->t('Irish'), |
| 100 | 'ig' => $this->t('Igbo'), |
| 101 | 'ik' => $this->t('Inupiaq'), |
| 102 | 'io' => $this->t('Ido'), |
| 103 | 'is' => $this->t('Icelandic'), |
| 104 | 'it' => $this->t('Italian'), |
| 105 | 'iu' => $this->t('Inuktitut'), |
| 106 | 'ja' => $this->t('Japanese'), |
| 107 | 'jv' => $this->t('Javanese'), |
| 108 | 'kl' => $this->t('Kalaallisut'), |
| 109 | 'kn' => $this->t('Kannada'), |
| 110 | 'kr' => $this->t('Kanuri'), |
| 111 | 'ks' => $this->t('Kashmiri'), |
| 112 | 'kk' => $this->t('Kazakh'), |
| 113 | 'km' => $this->t('Khmer'), |
| 114 | 'ki' => $this->t('Kikuyu'), |
| 115 | 'rw' => $this->t('Kinyarwanda'), |
| 116 | 'ky' => $this->t('Kyrgyz'), |
| 117 | 'kv' => $this->t('Komi'), |
| 118 | 'kg' => $this->t('Kongo'), |
| 119 | 'ko' => $this->t('Korean'), |
| 120 | 'ku' => $this->t('Kurdish'), |
| 121 | 'kj' => $this->t('Kwanyama'), |
| 122 | 'la' => $this->t('Latin'), |
| 123 | 'lb' => $this->t('Luxembourgish'), |
| 124 | 'lg' => $this->t('Ganda'), |
| 125 | 'li' => $this->t('Limburgish'), |
| 126 | 'ln' => $this->t('Lingala'), |
| 127 | 'lo' => $this->t('Lao'), |
| 128 | 'lt' => $this->t('Lithuanian'), |
| 129 | 'lu' => $this->t('Luba-Katanga'), |
| 130 | 'lv' => $this->t('Latvian'), |
| 131 | 'gv' => $this->t('Manx'), |
| 132 | 'mk' => $this->t('Macedonian'), |
| 133 | 'mg' => $this->t('Malagasy'), |
| 134 | 'ms' => $this->t('Malay'), |
| 135 | 'ml' => $this->t('Malayalam'), |
| 136 | 'mt' => $this->t('Maltese'), |
| 137 | 'mi' => $this->t('Māori'), |
| 138 | 'mr' => $this->t('Marathi (Marāṭhī)'), |
| 139 | 'mh' => $this->t('Marshallese'), |
| 140 | 'mn' => $this->t('Mongolian'), |
| 141 | 'na' => $this->t('Nauruan'), |
| 142 | 'nv' => $this->t('Navajo'), |
| 143 | 'nd' => $this->t('Northern Ndebele'), |
| 144 | 'ne' => $this->t('Nepali'), |
| 145 | 'ng' => $this->t('Ndonga'), |
| 146 | 'nb' => $this->t('Norwegian Bokmål'), |
| 147 | 'nn' => $this->t('Norwegian Nynorsk'), |
| 148 | 'no' => $this->t('Norwegian'), |
| 149 | 'ii' => $this->t('Nuosu'), |
| 150 | 'nr' => $this->t('Southern Ndebele'), |
| 151 | 'oc' => $this->t('Occitan'), |
| 152 | 'oj' => $this->t('Ojibwe'), |
| 153 | 'cu' => $this->t('Old Church Slavonic'), |
| 154 | 'om' => $this->t('Oromo'), |
| 155 | 'or' => $this->t('Oriya'), |
| 156 | 'os' => $this->t('Ossetian'), |
| 157 | 'pa' => $this->t('(Eastern) Punjabi'), |
| 158 | 'pi' => $this->t('Pāli'), |
| 159 | 'fa' => $this->t('Persian (Farsi)'), |
| 160 | 'pl' => $this->t('Polish'), |
| 161 | 'ps' => $this->t('Pashto'), |
| 162 | 'pt' => $this->t('Portuguese'), |
| 163 | 'qu' => $this->t('Quechua'), |
| 164 | 'rm' => $this->t('Romansh'), |
| 165 | 'rn' => $this->t('Kirundi'), |
| 166 | 'ro' => $this->t('Romanian'), |
| 167 | 'ru' => $this->t('Russian'), |
| 168 | 'sa' => $this->t('Sanskrit (Saṁskṛta)'), |
| 169 | 'sc' => $this->t('Sardinian'), |
| 170 | 'sd' => $this->t('Sindhi'), |
| 171 | 'se' => $this->t('Northern Sami'), |
| 172 | 'sm' => $this->t('Samoan'), |
| 173 | 'sg' => $this->t('Sango'), |
| 174 | 'sr' => $this->t('Serbian'), |
| 175 | 'gd' => $this->t('Scottish Gaelic'), |
| 176 | 'sn' => $this->t('Shona'), |
| 177 | 'si' => $this->t('Sinhalese'), |
| 178 | 'sk' => $this->t('Slovak'), |
| 179 | 'sl' => $this->t('Slovene'), |
| 180 | 'so' => $this->t('Somali'), |
| 181 | 'st' => $this->t('Southern Sotho'), |
| 182 | 'es' => $this->t('Spanish'), |
| 183 | 'su' => $this->t('Sundanese'), |
| 184 | 'sw' => $this->t('Swahili'), |
| 185 | 'ss' => $this->t('Swati'), |
| 186 | 'sv' => $this->t('Swedish'), |
| 187 | 'ta' => $this->t('Tamil'), |
| 188 | 'te' => $this->t('Telugu'), |
| 189 | 'tg' => $this->t('Tajik'), |
| 190 | 'th' => $this->t('Thai'), |
| 191 | 'ti' => $this->t('Tigrinya'), |
| 192 | 'bo' => $this->t('Tibetan Standard'), |
| 193 | 'tk' => $this->t('Turkmen'), |
| 194 | 'tl' => $this->t('Tagalog'), |
| 195 | 'tn' => $this->t('Tswana'), |
| 196 | 'to' => $this->t('Tonga (Tonga Islands)'), |
| 197 | 'tr' => $this->t('Turkish'), |
| 198 | 'ts' => $this->t('Tsonga'), |
| 199 | 'tt' => $this->t('Tatar'), |
| 200 | 'tw' => $this->t('Twi'), |
| 201 | 'ty' => $this->t('Tahitian'), |
| 202 | 'ug' => $this->t('Uyghur'), |
| 203 | 'uk' => $this->t('Ukrainian'), |
| 204 | 'ur' => $this->t('Urdu'), |
| 205 | 'uz' => $this->t('Uzbek'), |
| 206 | 've' => $this->t('Venda'), |
| 207 | 'vi' => $this->t('Vietnamese'), |
| 208 | 'vo' => $this->t('Volapük'), |
| 209 | 'wa' => $this->t('Walloon'), |
| 210 | 'cy' => $this->t('Welsh'), |
| 211 | 'wo' => $this->t('Wolof'), |
| 212 | 'fy' => $this->t('Western Frisian'), |
| 213 | 'xh' => $this->t('Xhosa'), |
| 214 | 'yi' => $this->t('Yiddish'), |
| 215 | 'yo' => $this->t('Yoruba'), |
| 216 | 'za' => $this->t('Zhuang'), |
| 217 | 'zu' => $this->t('Zulu'), |
| 218 | ]; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * {@inheritdoc} |
| 223 | */ |
| 224 | public function getLanguageLabel($language_code): MarkupInterface { |
| 225 | return $this->languages[$language_code] ?? $this->t('Unknown'); |
| 226 | } |
| 227 | |
| 228 | } |