20 #include "../util/btassert.h"
33 LanguageMap::LanguageMap() {
66 QObject::tr(
"Names of languages",
"No need to translate - see the longer comment (If there is no longer comment, it doesn't work yet :)) ------ ");
68 auto const addLanguage =
69 [
this](QStringList abbrevs, QString englishName) {
71 std::make_shared<Language>(std::move(abbrevs),
72 std::move(englishName));
73 for (
auto const & abbrev : language->abbrevs()) {
75 insert(abbrev, language);
82 addLanguage({QStringLiteral(
"af")}, QT_TRANSLATE_NOOP(
"QObject",
"Afrikaans"));
84 addLanguage({QStringLiteral(
"amu")}, QT_TRANSLATE_NOOP(
"QObject",
"Amuzgo, Guerrero"));
85 addLanguage({QStringLiteral(
"ang")}, QT_TRANSLATE_NOOP(
"QObject",
"English, Old (ca.450-1100)"));
86 addLanguage({QStringLiteral(
"ar")}, QT_TRANSLATE_NOOP(
"QObject",
"Arabic"));
88 addLanguage({QStringLiteral(
"az")}, QT_TRANSLATE_NOOP(
"QObject",
"Azerbaijani"));
89 addLanguage({QStringLiteral(
"azb")}, QT_TRANSLATE_NOOP(
"QObject",
"Azerbaijani, South"));
91 addLanguage({QStringLiteral(
"bar")}, QT_TRANSLATE_NOOP(
"QObject",
"Bavarian"));
92 addLanguage({QStringLiteral(
"be")}, QT_TRANSLATE_NOOP(
"QObject",
"Belarusian"));
93 addLanguage({QStringLiteral(
"bg")}, QT_TRANSLATE_NOOP(
"QObject",
"Bulgarian"));
98 addLanguage({QStringLiteral(
"br")}, QT_TRANSLATE_NOOP(
"QObject",
"Breton"));
99 addLanguage({QStringLiteral(
"bs")}, QT_TRANSLATE_NOOP(
"QObject",
"Bosnian"));
100 addLanguage({QStringLiteral(
"ca")}, QT_TRANSLATE_NOOP(
"QObject",
"Catalan"));
102 addLanguage({QStringLiteral(
"cco")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinantec, Comaltepec"));
103 addLanguage({QStringLiteral(
"ceb")}, QT_TRANSLATE_NOOP(
"QObject",
"Cebuano"));
104 addLanguage({QStringLiteral(
"ch")}, QT_TRANSLATE_NOOP(
"QObject",
"Chamorro"));
105 addLanguage({QStringLiteral(
"chd")}, QT_TRANSLATE_NOOP(
"QObject",
"Chontal, Highland Oaxaca"));
106 addLanguage({QStringLiteral(
"chq")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinantec, Quiotepec"));
107 addLanguage({QStringLiteral(
"chz")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinantec, Ozumac\u00edn"));
109 addLanguage({QStringLiteral(
"ckw")}, QT_TRANSLATE_NOOP(
"QObject",
"Cakchiquel, Western"));
110 addLanguage({QStringLiteral(
"cnl")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinantec, Lalana"));
111 addLanguage({QStringLiteral(
"cnt")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinantec, Tepetotutla"));
112 addLanguage({QStringLiteral(
"cop")}, QT_TRANSLATE_NOOP(
"QObject",
"Coptic"));
113 addLanguage({QStringLiteral(
"cs")}, QT_TRANSLATE_NOOP(
"QObject",
"Czech"));
114 addLanguage({QStringLiteral(
"cso")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinantec, Sochiapan"));
115 addLanguage({QStringLiteral(
"cti")}, QT_TRANSLATE_NOOP(
"QObject",
"Chol, Tila"));
116 addLanguage({QStringLiteral(
"ctp")}, QT_TRANSLATE_NOOP(
"QObject",
"Chatino, Western Highland"));
117 addLanguage({QStringLiteral(
"cu")}, QT_TRANSLATE_NOOP(
"QObject",
"Church Slavic"));
119 addLanguage({QStringLiteral(
"cy")}, QT_TRANSLATE_NOOP(
"QObject",
"Welsh"));
120 addLanguage({QStringLiteral(
"da")}, QT_TRANSLATE_NOOP(
"QObject",
"Danish"));
121 addLanguage({QStringLiteral(
"de")}, QT_TRANSLATE_NOOP(
"QObject",
"German"));
122 addLanguage({QStringLiteral(
"dug")}, QT_TRANSLATE_NOOP(
"QObject",
"Duruma"));
124 addLanguage({QStringLiteral(
"el"), QStringLiteral(
"gre"), QStringLiteral(
"ell")}, QT_TRANSLATE_NOOP(
"QObject",
"Greek, Modern (1453-)"));
125 addLanguage({QStringLiteral(
"en")}, QT_TRANSLATE_NOOP(
"QObject",
"English"));
126 addLanguage({QStringLiteral(
"en-US")}, QT_TRANSLATE_NOOP(
"QObject",
"American English"));
127 addLanguage({QStringLiteral(
"enm")}, QT_TRANSLATE_NOOP(
"QObject",
"English, Middle (1100-1500)"));
128 addLanguage({QStringLiteral(
"eo")}, QT_TRANSLATE_NOOP(
"QObject",
"Esperanto"));
129 addLanguage({QStringLiteral(
"es")}, QT_TRANSLATE_NOOP(
"QObject",
"Spanish"));
130 addLanguage({QStringLiteral(
"et")}, QT_TRANSLATE_NOOP(
"QObject",
"Estonian"));
131 addLanguage({QStringLiteral(
"eu")}, QT_TRANSLATE_NOOP(
"QObject",
"Basque"));
132 addLanguage({QStringLiteral(
"fa")}, QT_TRANSLATE_NOOP(
"QObject",
"Persian"));
133 addLanguage({QStringLiteral(
"fi")}, QT_TRANSLATE_NOOP(
"QObject",
"Finnish"));
136 addLanguage({QStringLiteral(
"fr")}, QT_TRANSLATE_NOOP(
"QObject",
"French"));
137 addLanguage({QStringLiteral(
"fy")}, QT_TRANSLATE_NOOP(
"QObject",
"Frisian"));
138 addLanguage({QStringLiteral(
"ga")}, QT_TRANSLATE_NOOP(
"QObject",
"Irish"));
139 addLanguage({QStringLiteral(
"gd")}, QT_TRANSLATE_NOOP(
"QObject",
"Gaelic (Scots)"));
140 addLanguage({QStringLiteral(
"gez")}, QT_TRANSLATE_NOOP(
"QObject",
"Geez"));
144 addLanguage({QStringLiteral(
"got")}, QT_TRANSLATE_NOOP(
"QObject",
"Gothic"));
145 addLanguage({QStringLiteral(
"gv")}, QT_TRANSLATE_NOOP(
"QObject",
"Manx"));
146 addLanguage({QStringLiteral(
"grc")}, QT_TRANSLATE_NOOP(
"QObject",
"Greek, Ancient (to 1453)"));
147 addLanguage({QStringLiteral(
"hau")}, QT_TRANSLATE_NOOP(
"QObject",
"Hausa"));
148 addLanguage({QStringLiteral(
"haw")}, QT_TRANSLATE_NOOP(
"QObject",
"Hawaiian"));
149 addLanguage({QStringLiteral(
"hbo")}, QT_TRANSLATE_NOOP(
"QObject",
"Hebrew, Ancient"));
150 addLanguage({QStringLiteral(
"he")}, QT_TRANSLATE_NOOP(
"QObject",
"Hebrew"));
151 addLanguage({QStringLiteral(
"hi")}, QT_TRANSLATE_NOOP(
"QObject",
"Hindi"));
153 addLanguage({QStringLiteral(
"hr")}, QT_TRANSLATE_NOOP(
"QObject",
"Croatian"));
154 addLanguage({QStringLiteral(
"ht")}, QT_TRANSLATE_NOOP(
"QObject",
"Haitian Creole"));
155 addLanguage({QStringLiteral(
"hu")}, QT_TRANSLATE_NOOP(
"QObject",
"Hungarian"));
156 addLanguage({QStringLiteral(
"huv")}, QT_TRANSLATE_NOOP(
"QObject",
"Huave, San Mateo Del Mar"));
157 addLanguage({QStringLiteral(
"hy")}, QT_TRANSLATE_NOOP(
"QObject",
"Armenian"));
160 addLanguage({QStringLiteral(
"id")}, QT_TRANSLATE_NOOP(
"QObject",
"Indonesian"));
163 addLanguage({QStringLiteral(
"is")}, QT_TRANSLATE_NOOP(
"QObject",
"Icelandic"));
164 addLanguage({QStringLiteral(
"it")}, QT_TRANSLATE_NOOP(
"QObject",
"Italian"));
165 addLanguage({QStringLiteral(
"itz")}, QT_TRANSLATE_NOOP(
"QObject",
"Itz\u00e1"));
166 addLanguage({QStringLiteral(
"ixl")}, QT_TRANSLATE_NOOP(
"QObject",
"Ixil, San Juan Cotzal"));
168 addLanguage({QStringLiteral(
"ja")}, QT_TRANSLATE_NOOP(
"QObject",
"Japanese"));
169 addLanguage({QStringLiteral(
"jac")}, QT_TRANSLATE_NOOP(
"QObject",
"Jacalteco, Eastern"));
170 addLanguage({QStringLiteral(
"jvn")}, QT_TRANSLATE_NOOP(
"QObject",
"Javanese, Caribbean"));
171 addLanguage({QStringLiteral(
"ka")}, QT_TRANSLATE_NOOP(
"QObject",
"Georgian"));
172 addLanguage({QStringLiteral(
"kek")}, QT_TRANSLATE_NOOP(
"QObject",
"Kekchi"));
179 addLanguage({QStringLiteral(
"ko")}, QT_TRANSLATE_NOOP(
"QObject",
"Korean"));
181 addLanguage({QStringLiteral(
"ku")}, QT_TRANSLATE_NOOP(
"QObject",
"Kurdish"));
184 addLanguage({QStringLiteral(
"ky")}, QT_TRANSLATE_NOOP(
"QObject",
"Kirghiz"));
185 addLanguage({QStringLiteral(
"la")}, QT_TRANSLATE_NOOP(
"QObject",
"Latin"));
186 addLanguage({QStringLiteral(
"lac")}, QT_TRANSLATE_NOOP(
"QObject",
"Lacandon"));
188 addLanguage({QStringLiteral(
"lmo")}, QT_TRANSLATE_NOOP(
"QObject",
"Lombard"));
191 addLanguage({QStringLiteral(
"lt")}, QT_TRANSLATE_NOOP(
"QObject",
"Lithuanian"));
192 addLanguage({QStringLiteral(
"lv")}, QT_TRANSLATE_NOOP(
"QObject",
"Latvian"));
193 addLanguage({QStringLiteral(
"mg")}, QT_TRANSLATE_NOOP(
"QObject",
"Malagasy"));
195 addLanguage({QStringLiteral(
"mi")}, QT_TRANSLATE_NOOP(
"QObject",
"Maori"));
196 addLanguage({QStringLiteral(
"mir")}, QT_TRANSLATE_NOOP(
"QObject",
"Mixe, Isthmus"));
197 addLanguage({QStringLiteral(
"miz")}, QT_TRANSLATE_NOOP(
"QObject",
"Mixtec, Coatzospan"));
198 addLanguage({QStringLiteral(
"mk")}, QT_TRANSLATE_NOOP(
"QObject",
"Macedonian"));
199 addLanguage({QStringLiteral(
"mks")}, QT_TRANSLATE_NOOP(
"QObject",
"Mixtec, Silacayoapan"));
203 addLanguage({QStringLiteral(
"mos")}, QT_TRANSLATE_NOOP(
"QObject",
"More"));
205 addLanguage({QStringLiteral(
"ms")}, QT_TRANSLATE_NOOP(
"QObject",
"Malay"));
206 addLanguage({QStringLiteral(
"mt")}, QT_TRANSLATE_NOOP(
"QObject",
"Maltese"));
207 addLanguage({QStringLiteral(
"mul")}, QT_TRANSLATE_NOOP(
"QObject",
"(Multiple languages)"));
208 addLanguage({QStringLiteral(
"mvc")}, QT_TRANSLATE_NOOP(
"QObject",
"Mam, Central"));
209 addLanguage({QStringLiteral(
"mvj")}, QT_TRANSLATE_NOOP(
"QObject",
"Mam, Todos Santos Cuchumat\u00e1n"));
210 addLanguage({QStringLiteral(
"mxq")}, QT_TRANSLATE_NOOP(
"QObject",
"Mixe, Juquila"));
211 addLanguage({QStringLiteral(
"mxt")}, QT_TRANSLATE_NOOP(
"QObject",
"Mixtec, Jamiltepec"));
212 addLanguage({QStringLiteral(
"my")}, QT_TRANSLATE_NOOP(
"QObject",
"Burmese"));
214 addLanguage({QStringLiteral(
"nb")}, QT_TRANSLATE_NOOP(
"QObject",
"Norwegian Bokm\u00e5l"));
215 addLanguage({QStringLiteral(
"ncl")}, QT_TRANSLATE_NOOP(
"QObject",
"Nahuatl, Michoac\u00e1n"));
217 addLanguage({QStringLiteral(
"nds")}, QT_TRANSLATE_NOOP(
"QObject",
"Low German; Low Saxon"));
218 addLanguage({QStringLiteral(
"ne")}, QT_TRANSLATE_NOOP(
"QObject",
"Nepali"));
219 addLanguage({QStringLiteral(
"ngu")}, QT_TRANSLATE_NOOP(
"QObject",
"Nahuatl, Guerrero"));
220 addLanguage({QStringLiteral(
"nhy")}, QT_TRANSLATE_NOOP(
"QObject",
"Nahuatl, Northern Oaxaca"));
222 addLanguage({QStringLiteral(
"nl")}, QT_TRANSLATE_NOOP(
"QObject",
"Dutch"));
223 addLanguage({QStringLiteral(
"nn")}, QT_TRANSLATE_NOOP(
"QObject",
"Norwegian Nynorsk"));
224 addLanguage({QStringLiteral(
"no")}, QT_TRANSLATE_NOOP(
"QObject",
"Norwegian"));
232 addLanguage({QStringLiteral(
"otq")}, QT_TRANSLATE_NOOP(
"QObject",
"Otomi, Quer\u00e9taro"));
234 addLanguage({QStringLiteral(
"pap")}, QT_TRANSLATE_NOOP(
"QObject",
"Papiamento"));
236 addLanguage({QStringLiteral(
"pl")}, QT_TRANSLATE_NOOP(
"QObject",
"Polish"));
237 addLanguage({QStringLiteral(
"pot")}, QT_TRANSLATE_NOOP(
"QObject",
"Potawatomi"));
238 addLanguage({QStringLiteral(
"ppk")}, QT_TRANSLATE_NOOP(
"QObject",
"Uma"));
239 addLanguage({QStringLiteral(
"prs")}, QT_TRANSLATE_NOOP(
"QObject",
"Persian (Dari)"));
241 addLanguage({QStringLiteral(
"pt")}, QT_TRANSLATE_NOOP(
"QObject",
"Portuguese"));
242 addLanguage({QStringLiteral(
"pt-BR")}, QT_TRANSLATE_NOOP(
"QObject",
"Brazilian Portuguese"));
244 addLanguage({QStringLiteral(
"qut")}, QT_TRANSLATE_NOOP(
"QObject",
"Quich\u00e9, West Central"));
247 addLanguage({QStringLiteral(
"ro")}, QT_TRANSLATE_NOOP(
"QObject",
"Romanian"));
248 addLanguage({QStringLiteral(
"ru")}, QT_TRANSLATE_NOOP(
"QObject",
"Russian"));
252 addLanguage({QStringLiteral(
"sco")}, QT_TRANSLATE_NOOP(
"QObject",
"Scots"));
257 addLanguage({QStringLiteral(
"sk")}, QT_TRANSLATE_NOOP(
"QObject",
"Slovak"));
258 addLanguage({QStringLiteral(
"sl")}, QT_TRANSLATE_NOOP(
"QObject",
"Slovenian"));
261 addLanguage({QStringLiteral(
"so")}, QT_TRANSLATE_NOOP(
"QObject",
"Somali"));
262 addLanguage({QStringLiteral(
"sq")}, QT_TRANSLATE_NOOP(
"QObject",
"Albanian"));
264 addLanguage({QStringLiteral(
"srn")}, QT_TRANSLATE_NOOP(
"QObject",
"Sranan"));
268 addLanguage({QStringLiteral(
"sv")}, QT_TRANSLATE_NOOP(
"QObject",
"Swedish"));
269 addLanguage({QStringLiteral(
"sw")}, QT_TRANSLATE_NOOP(
"QObject",
"Swahili"));
270 addLanguage({QStringLiteral(
"syr")}, QT_TRANSLATE_NOOP(
"QObject",
"Syriac"));
271 addLanguage({QStringLiteral(
"ta")}, QT_TRANSLATE_NOOP(
"QObject",
"Tamil"));
274 addLanguage({QStringLiteral(
"th")}, QT_TRANSLATE_NOOP(
"QObject",
"Thai"));
276 addLanguage({QStringLiteral(
"tl")}, QT_TRANSLATE_NOOP(
"QObject",
"Tagalog"));
277 addLanguage({QStringLiteral(
"tlh")}, QT_TRANSLATE_NOOP(
"QObject",
"Klingon"));
278 addLanguage({QStringLiteral(
"tn")}, QT_TRANSLATE_NOOP(
"QObject",
"Tswana"));
279 addLanguage({QStringLiteral(
"tr")}, QT_TRANSLATE_NOOP(
"QObject",
"Turkish"));
282 addLanguage({QStringLiteral(
"ttc")}, QT_TRANSLATE_NOOP(
"QObject",
"Tektiteko"));
284 addLanguage({QStringLiteral(
"ty")}, QT_TRANSLATE_NOOP(
"QObject",
"Tahitian"));
285 addLanguage({QStringLiteral(
"tzz")}, QT_TRANSLATE_NOOP(
"QObject",
"Tzotzil, Zinacant\u00e1n"));
287 addLanguage({QStringLiteral(
"uk")}, QT_TRANSLATE_NOOP(
"QObject",
"Ukrainian"));
289 addLanguage({QStringLiteral(
"ury")}, QT_TRANSLATE_NOOP(
"QObject",
"Orya"));
290 addLanguage({QStringLiteral(
"usp")}, QT_TRANSLATE_NOOP(
"QObject",
"Uspanteco"));
292 addLanguage({QStringLiteral(
"vi")}, QT_TRANSLATE_NOOP(
"QObject",
"Vietnamese"));
295 addLanguage({QStringLiteral(
"xh")}, QT_TRANSLATE_NOOP(
"QObject",
"Xhosa"));
296 addLanguage({QStringLiteral(
"xtd")}, QT_TRANSLATE_NOOP(
"QObject",
"Mixtec, Diuxi-Tilantongo"));
297 addLanguage({QStringLiteral(
"yi")}, QT_TRANSLATE_NOOP(
"QObject",
"Yiddish"));
298 addLanguage({QStringLiteral(
"yo")}, QT_TRANSLATE_NOOP(
"QObject",
"Yoruba"));
300 addLanguage({QStringLiteral(
"zab")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, San Juan Guelav\u00eda"));
301 addLanguage({QStringLiteral(
"zaw")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Mitla"));
302 addLanguage({QStringLiteral(
"zh")}, QT_TRANSLATE_NOOP(
"QObject",
"Chinese"));
303 addLanguage({QStringLiteral(
"zpo")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Amatl\u00e1n"));
304 addLanguage({QStringLiteral(
"zpq")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Zoogocho"));
305 addLanguage({QStringLiteral(
"zpu")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Yal\u00e1lag"));
306 addLanguage({QStringLiteral(
"zpv")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Chichicapan"));
307 addLanguage({QStringLiteral(
"zsr")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Southern Rincon"));
308 addLanguage({QStringLiteral(
"ztq")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Quioquitani-Quier\u00ed"));
309 addLanguage({QStringLiteral(
"zty")}, QT_TRANSLATE_NOOP(
"QObject",
"Zapotec, Yatee"));
310 addLanguage({QStringLiteral(
"zu")}, QT_TRANSLATE_NOOP(
"QObject",
"Zulu"));
316 : m_abbrevs(std::move(abbrevs))
317 , m_englishName(std::move(englishName))
332 static LanguageMap languageMap;
334 BT_ASSERT(languageMap.contains(QStringLiteral(
"en")));
335 static auto const defaultLanguage = *languageMap.find(QStringLiteral(
"en"));
337 return defaultLanguage;
339 auto it(languageMap.find(
abbrev));
340 if (it != languageMap.constEnd())
350 auto const abbrevEn =
abbrev + QStringLiteral(
".en");
354 abbrevEn.toUtf8().constData())));
364 QStringList tryTranslateNames;
366 auto localeName = QLocale().name();
367 while (!localeName.isEmpty()
368 && localeName != QStringLiteral(
"en"))
370 tryTranslateNames.append(
abbrev() +
'.' + localeName);
371 if (localeName ==
abbrev())
372 tryTranslateNames.append(localeName);
373 while (localeName.back().isLetterOrNumber()) {
375 if (localeName.isEmpty())
378 while (!localeName.isEmpty()
379 && !localeName.back().isLetterOrNumber())
383 for (
auto const & translateName : tryTranslateNames) {
387 translateName.toUtf8().constData()));
388 if (trName != translateName)
397 auto newLang = std::make_shared<SwordLanguage>(QStringList{
abbrev},
abbrev);
398 languageMap.insert(
abbrev, newLang);
Language(Language &&)=delete
static std::shared_ptr< Language const > fromAbbrev(QString const &abbrev)
QString const m_englishName
QString const & englishName() const noexcept
QString const & abbrev() const
virtual QString translatedName() const
QStringList const & abbrevs() const
QStringList const m_abbrevs
sword::SWLocale * localeTranslator()