diff options
| author | Petr Mrázek <peterix@users.noreply.github.com> | 2021-07-22 18:15:46 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-22 18:15:46 +0200 | 
| commit | 9e9281f06ee212fd037dc309084203f0d06f234e (patch) | |
| tree | 50501f5b9cda45bd0ec55700ebfe784d0563bdec /api/logic | |
| parent | 6f12b31ead960e2f8827fa33b3f6ef979953a8bf (diff) | |
| parent | 88ce42bc0a170e97f77320e7ee5eb60b8dc0c135 (diff) | |
| download | PrismLauncher-9e9281f06ee212fd037dc309084203f0d06f234e.tar.gz PrismLauncher-9e9281f06ee212fd037dc309084203f0d06f234e.tar.bz2 PrismLauncher-9e9281f06ee212fd037dc309084203f0d06f234e.zip | |
Merge pull request #3728 from jamierocks/sort-languages
NOISSUE Sort languages alphabetically by their key
Diffstat (limited to 'api/logic')
| -rw-r--r-- | api/logic/translations/TranslationsModel.cpp | 25 | 
1 files changed, 8 insertions, 17 deletions
| diff --git a/api/logic/translations/TranslationsModel.cpp b/api/logic/translations/TranslationsModel.cpp index 401b64d4..29a952b0 100644 --- a/api/logic/translations/TranslationsModel.cpp +++ b/api/logic/translations/TranslationsModel.cpp @@ -17,18 +17,6 @@  const static QLatin1Literal defaultLangCode("en_US"); -static QLocale getLocaleFromKey(const QString &key) { -    if(key == "pt") { -        return QLocale("pt_PT"); -    } -    else if (key == "en") { -        return QLocale("en_GB"); -    } -    else { -        return QLocale(key); -    } -} -  enum class FileType  {      NONE, @@ -45,7 +33,7 @@ struct Language      Language(const QString & _key)      {          key = _key; -        locale = getLocaleFromKey(key); +        locale = QLocale(key);          updated = (key == defaultLangCode);      } @@ -310,11 +298,14 @@ void TranslationsModel::reloadLocalFiles()      {          return;      } -    beginInsertRows(QModelIndex(), d->m_languages.size(), d->m_languages.size() + languages.size() - 1); +    beginInsertRows(QModelIndex(), 0, d->m_languages.size() + languages.size() - 1);      for(auto & language: languages)      {          d->m_languages.append(language);      } +    std::sort(d->m_languages.begin(), d->m_languages.end(), [](const Language& a, const Language& b) { +        return a.key.compare(b.key) < 0; +    });      endInsertRows();  } @@ -347,7 +338,7 @@ QVariant TranslationsModel::data(const QModelIndex& index, int role) const          {              case Column::Language:              { -                return d->m_languages[row].locale.nativeLanguageName(); +                return lang.locale.nativeLanguageName();              }              case Column::Completeness:              { @@ -362,7 +353,7 @@ QVariant TranslationsModel::data(const QModelIndex& index, int role) const          return tr("%1:\n%2 translated\n%3 fuzzy\n%4 total").arg(lang.key, QString::number(lang.translated), QString::number(lang.fuzzy), QString::number(lang.total));      }      case Qt::UserRole: -        return d->m_languages[row].key; +        return lang.key;      default:          return QVariant();      } @@ -459,7 +450,7 @@ bool TranslationsModel::selectLanguage(QString key)       * In a multithreaded application, the default locale should be set at application startup, before any non-GUI threads are created.       * This function is not reentrant.       */ -    QLocale locale = getLocaleFromKey(langCode); +    QLocale locale = QLocale(langCode);      QLocale::setDefault(locale);      // if it's the default UI language, finish | 
