Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 96e49c12 authored by Laurent Montel's avatar Laurent Montel 😁

Fix generate list of languages

parent 6ff70422
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment