File indexing completed on 2024-05-12 16:16:02
0001 /* 0002 SPDX-FileCopyrightText: 2019-2023 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "languagetoolcombobox.h" 0008 #include "languageinfo.h" 0009 #include <KLocalizedString> 0010 using namespace TextGrammarCheck; 0011 LanguageToolComboBox::LanguageToolComboBox(QWidget *parent) 0012 : QComboBox(parent) 0013 { 0014 fillComboBox(); 0015 } 0016 0017 LanguageToolComboBox::~LanguageToolComboBox() = default; 0018 0019 void LanguageToolComboBox::fillComboBox(const QVector<LanguageInfo> &info) 0020 { 0021 clear(); 0022 for (int i = 0; i < info.count(); ++i) { 0023 const LanguageInfo infoLang = info.at(i); 0024 addItem(infoLang.name(), infoLang.code()); 0025 } 0026 } 0027 0028 void LanguageToolComboBox::fillComboBox() 0029 { 0030 // TODO add more 0031 addItem(i18n("English"), QStringLiteral("en")); 0032 addItem(i18n("Asturian"), QStringLiteral("ast")); 0033 addItem(i18n("Belarusian"), QStringLiteral("be")); 0034 addItem(i18n("Breton"), QStringLiteral("br")); 0035 addItem(i18n("Catalan"), QStringLiteral("ca")); 0036 addItem(i18n("Chinese"), QStringLiteral("zh")); 0037 addItem(i18n("Danish"), QStringLiteral("da")); 0038 addItem(i18n("Dutch"), QStringLiteral("nl")); 0039 addItem(i18n("English (Australian)"), QStringLiteral("en-AU")); 0040 addItem(i18n("English (Canadian)"), QStringLiteral("en-CA")); 0041 addItem(i18n("Esperanto"), QStringLiteral("eo")); 0042 addItem(i18n("French"), QStringLiteral("fr")); 0043 addItem(i18n("Galician"), QStringLiteral("gl")); 0044 addItem(i18n("German"), QStringLiteral("de")); 0045 addItem(i18n("Greek"), QStringLiteral("el")); 0046 addItem(i18n("Italian"), QStringLiteral("it")); 0047 addItem(i18n("Japanese"), QStringLiteral("ja")); 0048 addItem(i18n("Khmer"), QStringLiteral("km")); 0049 addItem(i18n("Persian"), QStringLiteral("fa")); 0050 addItem(i18n("Polish"), QStringLiteral("pl")); 0051 addItem(i18n("Portuguese"), QStringLiteral("pt")); 0052 addItem(i18n("Romanian"), QStringLiteral("ro")); 0053 addItem(i18n("Russian"), QStringLiteral("ru")); 0054 addItem(i18n("Slovak"), QStringLiteral("sk")); 0055 addItem(i18n("Slovenian"), QStringLiteral("sl")); 0056 addItem(i18n("Spanish"), QStringLiteral("es")); 0057 addItem(i18n("Swedish"), QStringLiteral("sv")); 0058 addItem(i18n("Tagalog"), QStringLiteral("tl")); 0059 addItem(i18n("Tamil"), QStringLiteral("ta")); 0060 addItem(i18n("Ukrainian"), QStringLiteral("uk-UA")); 0061 } 0062 0063 void LanguageToolComboBox::setLanguage(const QString &str) 0064 { 0065 const int pos = findData(str); 0066 if (pos != -1) { 0067 setCurrentIndex(pos); 0068 } 0069 } 0070 0071 QString LanguageToolComboBox::language() const 0072 { 0073 return currentData().toString(); 0074 } 0075 0076 #include "moc_languagetoolcombobox.cpp"