7#include "translatorutil.h"
9#include "texttranslator_debug.h"
10#include <KConfigGroup>
11#include <KLocalizedString>
12#include <KSharedConfig>
16using namespace TextTranslator;
17TranslatorUtil::TranslatorUtil() =
default;
22 for (
int i = TranslatorUtil::Language::automatic; i < TranslatorUtil::Language::lastLanguage; ++i) {
23 map.insert(
static_cast<TranslatorUtil::Language
>(i), translatedLanguage(
static_cast<TranslatorUtil::Language
>(i)));
28QString TranslatorUtil::translatedLanguage(TranslatorUtil::Language lang)
33 ret =
i18n(
"Detect language");
39 ret =
i18n(
"Bosnian");
42 ret =
i18n(
"English");
45 ret =
i18n(
"Chinese (Simplified)");
48 ret =
i18n(
"Chinese (Traditional)");
63 ret =
i18n(
"Italian");
66 ret =
i18n(
"Japanese");
72 ret =
i18n(
"Portuguese");
75 ret =
i18n(
"Russian");
78 ret =
i18n(
"Spanish");
81 ret =
i18n(
"Afrikaans");
84 ret =
i18n(
"Albanian");
90 ret =
i18n(
"Armenian");
93 ret =
i18n(
"Azerbaijani");
99 ret =
i18n(
"Belarusian");
102 ret =
i18n(
"Bulgarian");
105 ret =
i18n(
"Catalan");
108 ret =
i18n(
"Croatian");
114 ret =
i18n(
"Danish");
117 ret =
i18n(
"Estonian");
120 ret =
i18n(
"Filipino");
123 ret =
i18n(
"Finnish");
126 ret =
i18n(
"Galician");
129 ret =
i18n(
"Georgian");
132 ret =
i18n(
"Haitian Creole");
135 ret =
i18n(
"Hebrew");
141 ret =
i18n(
"Hungarian");
144 ret =
i18n(
"Icelandic");
147 ret =
i18n(
"Indonesian");
153 ret =
i18n(
"Latvian");
156 ret =
i18n(
"Lithuanian");
159 ret =
i18n(
"Macedonian");
165 ret =
i18n(
"Maltese");
168 ret =
i18n(
"Norwegian");
171 ret =
i18n(
"Persian");
174 ret =
i18n(
"Polish");
177 ret =
i18n(
"Romanian");
180 ret =
i18n(
"Serbian");
183 ret =
i18n(
"Slovak");
186 ret =
i18n(
"Slovenian");
189 ret =
i18n(
"Swahili");
192 ret =
i18n(
"Swedish");
198 ret =
i18n(
"Turkish");
201 ret =
i18n(
"Ukrainian");
207 ret =
i18n(
"Vietnamese");
213 ret =
i18n(
"Yiddish");
219QString TranslatorUtil::searchI18nFromLanguage(
const QString &langCode)
221 for (
int i = TranslatorUtil::Language::automatic; i < TranslatorUtil::Language::lastLanguage; ++i) {
222 if (langCode == languageCode(
static_cast<TranslatorUtil::Language
>(i))) {
223 return translatedLanguage(
static_cast<TranslatorUtil::Language
>(i));
229TranslatorUtil::Language TranslatorUtil::stringToLanguage(
const QString &str)
231 if (str ==
"en"_L1) {
232 return TranslatorUtil::en;
233 }
else if (str ==
"fr"_L1) {
234 return TranslatorUtil::fr;
235 }
else if (str ==
"es"_L1) {
236 return TranslatorUtil::es;
237 }
else if (str ==
"pl"_L1) {
238 return TranslatorUtil::pl;
239 }
else if (str ==
"de"_L1) {
240 return TranslatorUtil::de;
241 }
else if (str ==
"cs"_L1) {
242 return TranslatorUtil::cs;
243 }
else if (str ==
"bg"_L1) {
244 return TranslatorUtil::bg;
245 }
else if (str ==
"et"_L1) {
246 return TranslatorUtil::et;
250 qCWarning(TEXTTRANSLATOR_LOG) <<
" Impossible to find TranslatorUtil::Language for " << str;
252 return TranslatorUtil::en;
255QString TranslatorUtil::languageCode(TranslatorUtil::Language lang)
260 ret = QStringLiteral(
"auto");
263 ret = QStringLiteral(
"hmn");
266 ret = QStringLiteral(
"en");
269 ret = QStringLiteral(
"zh-CN");
272 ret = QStringLiteral(
"zh-TW");
275 ret = QStringLiteral(
"nl");
278 ret = QStringLiteral(
"fr");
281 ret = QStringLiteral(
"de");
284 ret = QStringLiteral(
"el");
287 ret = QStringLiteral(
"it");
290 ret = QStringLiteral(
"ja");
293 ret = QStringLiteral(
"ko");
296 ret = QStringLiteral(
"pt");
299 ret = QStringLiteral(
"ru");
302 ret = QStringLiteral(
"es");
305 ret = QStringLiteral(
"af");
308 ret = QStringLiteral(
"sq");
311 ret = QStringLiteral(
"ar");
314 ret = QStringLiteral(
"hy");
317 ret = QStringLiteral(
"az");
320 ret = QStringLiteral(
"eu");
323 ret = QStringLiteral(
"be");
326 ret = QStringLiteral(
"bg");
329 ret = QStringLiteral(
"ca");
332 ret = QStringLiteral(
"hr");
335 ret = QStringLiteral(
"cs");
338 ret = QStringLiteral(
"da");
341 ret = QStringLiteral(
"et");
344 ret = QStringLiteral(
"tl");
347 ret = QStringLiteral(
"fi");
350 ret = QStringLiteral(
"gl");
353 ret = QStringLiteral(
"ka");
356 ret = QStringLiteral(
"ht");
359 ret = QStringLiteral(
"he");
362 ret = QStringLiteral(
"hi");
365 ret = QStringLiteral(
"hu");
368 ret = QStringLiteral(
"is");
371 ret = QStringLiteral(
"id");
374 ret = QStringLiteral(
"ga");
377 ret = QStringLiteral(
"lv");
380 ret = QStringLiteral(
"lt");
383 ret = QStringLiteral(
"mk");
386 ret = QStringLiteral(
"ms");
389 ret = QStringLiteral(
"mt");
392 ret = QStringLiteral(
"no");
395 ret = QStringLiteral(
"fa");
398 ret = QStringLiteral(
"pl");
401 ret = QStringLiteral(
"ro");
404 ret = QStringLiteral(
"sr");
407 ret = QStringLiteral(
"sk");
410 ret = QStringLiteral(
"sl");
413 ret = QStringLiteral(
"sw");
416 ret = QStringLiteral(
"sv");
419 ret = QStringLiteral(
"th");
422 ret = QStringLiteral(
"tr");
425 ret = QStringLiteral(
"uk");
428 ret = QStringLiteral(
"ur");
431 ret = QStringLiteral(
"vi");
434 ret = QStringLiteral(
"cy");
437 ret = QStringLiteral(
"yi");
440 return QStringLiteral(
"bs");
445void TranslatorUtil::addItemToFromComboBox(
QComboBox *combo,
const QString &languageCode,
const QString &translatedStr)
447 combo->
addItem(translatedStr, languageCode);
450QString TranslatorUtil::groupTranslateName()
452 return QStringLiteral(
"Translate");
455QString TranslatorUtil::engineTranslateName()
457 return QStringLiteral(
"engine");
460QString TranslatorUtil::defaultEngineName()
462 return QStringLiteral(
"google");
465QString TranslatorUtil::loadEngine()
468 const QString engineTypeStr = myGeneralGroup.readEntry(engineTranslateName(), defaultEngineName());
469 return engineTypeStr;
472void TranslatorUtil::saveEngineSettings(
const QString &engineName)
475 myGroup.writeEntry(engineTranslateName(), engineName);
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
QString i18n(const char *text, const TYPE &arg...)
void addItem(const QIcon &icon, const QString &text, const QVariant &userData)
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)