summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-12-01 13:26:19 +0100
committerMontel Laurent <[email protected]>2017-12-01 13:26:19 +0100
commit96e49c1282c74c356e378755bb175ba68dba8595 (patch)
tree91355bea12350ba748e211523b0598ee62673ed9
parent6ff704221fd154d6e9c1a5b26a18860aff3615bf (diff)
Fix generate list of languages
-rw-r--r--src/pimcommon/autocorrection/autocorrectionlanguage.cpp41
-rw-r--r--src/pimcommon/autocorrection/autocorrectionlanguage.h2
2 files changed, 35 insertions, 8 deletions
diff --git a/src/pimcommon/autocorrection/autocorrectionlanguage.cpp b/src/pimcommon/autocorrection/autocorrectionlanguage.cpp
index 4f7b010..c4b8dd8 100644
--- a/src/pimcommon/autocorrection/autocorrectionlanguage.cpp
+++ b/src/pimcommon/autocorrection/autocorrectionlanguage.cpp
@@ -17,19 +17,46 @@
#include "autocorrectionlanguage.h"
#include <QLocale>
+#include <QDebug>
using namespace PimCommon;
+static bool stripCountryCode(QString *languageCode)
+{
+ const int idx = languageCode->indexOf(QLatin1String("_"));
+ if (idx != -1) {
+ *languageCode = languageCode->left(idx);
+ return true;
+ }
+ return false;
+}
+
AutoCorrectionLanguage::AutoCorrectionLanguage(QWidget *parent)
- : KComboBox(parent)
+ : QComboBox(parent)
{
- for (int i = QLocale::Abkhazian; i <= QLocale::LastLanguage; ++i) {
- const auto lang = static_cast<QLocale::Language>(i);
- QLocale locale(lang);
- if (locale.name() == QLatin1String("C")) {
- continue;
+ QLocale cLocale(QLocale::C);
+ QSet<QString> insertedLanguages;
+ const QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
+ for (const QLocale &lang : allLocales) {
+ QString languageCode = lang.name();
+ if (lang != cLocale) {
+ const QString nativeName = lang.nativeLanguageName();
+ // For some languages the native name might be empty.
+ // In this case use the non native language name as fallback.
+ // See: QTBUG-51323
+ QString languageName = nativeName.isEmpty() ? QLocale::languageToString(lang.language()) : nativeName;
+ languageName = languageName.toLower();
+ if (!insertedLanguages.contains(languageName)) {
+ addItem(languageName, languageCode);
+ insertedLanguages << languageName;
+ } else if (stripCountryCode(&languageCode)) {
+ if (!insertedLanguages.contains(languageName)) {
+ addItem(languageName, languageCode);
+ insertedLanguages << languageName;
+ }
+ }
}
- addItem(QLocale::system().languageToString(lang), locale.name());
}
+
QString defaultLang;
if (!QLocale::system().uiLanguages().isEmpty()) {
defaultLang = QLocale::system().uiLanguages().at(0);
diff --git a/src/pimcommon/autocorrection/autocorrectionlanguage.h b/src/pimcommon/autocorrection/autocorrectionlanguage.h
index c273902..57423a1 100644
--- a/src/pimcommon/autocorrection/autocorrectionlanguage.h
+++ b/src/pimcommon/autocorrection/autocorrectionlanguage.h
@@ -22,7 +22,7 @@
#include "pimcommon_export.h"
namespace PimCommon {
-class PIMCOMMON_EXPORT AutoCorrectionLanguage : public KComboBox
+class PIMCOMMON_EXPORT AutoCorrectionLanguage : public QComboBox
{
public:
explicit AutoCorrectionLanguage(QWidget *parent);