summaryrefslogtreecommitdiffstats
path: root/src/linguist/linguist/translationsettingsdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linguist/linguist/translationsettingsdialog.cpp')
-rw-r--r--src/linguist/linguist/translationsettingsdialog.cpp97
1 files changed, 38 insertions, 59 deletions
diff --git a/src/linguist/linguist/translationsettingsdialog.cpp b/src/linguist/linguist/translationsettingsdialog.cpp
index 919258c6e..b75c8c4ac 100644
--- a/src/linguist/linguist/translationsettingsdialog.cpp
+++ b/src/linguist/linguist/translationsettingsdialog.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Linguist of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "translationsettingsdialog.h"
@@ -41,14 +16,16 @@ TranslationSettingsDialog::TranslationSettingsDialog(QWidget *parent)
m_ui.setupUi(this);
for (int i = QLocale::C + 1; i < QLocale::LastLanguage; ++i) {
- QString lang = QLocale::languageToString(QLocale::Language(i));
- auto loc = QLocale(QLocale::Language(i));
- if (loc.language() != QLocale::English) {
- QString nln = loc.nativeLanguageName();
- if (!nln.isEmpty()) {
- //: <english> (<endonym>) (language and country names)
- lang = tr("%1 (%2)").arg(lang, nln);
- }
+ const auto language = QLocale::Language(i);
+ QString lang = QLocale::languageToString(language);
+ const auto loc = QLocale(language);
+ // Languages for which we have no data get mapped to the default locale;
+ // its endonym is unrelated to the language requested. For English, the
+ // endonym is the name we already have; don't repeat it.
+ if (loc.language() == language && language != QLocale::English) {
+ const QString native = loc.nativeLanguageName();
+ if (!native.isEmpty()) //: <english> (<endonym>) (language names)
+ lang = tr("%1 (%2)").arg(lang, native);
}
m_ui.srcCbLanguageList->addItem(lang, QVariant(i));
}
@@ -74,35 +51,37 @@ void TranslationSettingsDialog::setPhraseBook(PhraseBook *phraseBook)
setWindowTitle(tr("Settings for '%1' - Qt Linguist").arg(fn));
}
-static void fillCountryCombo(const QVariant &lng, QComboBox *combo)
+static void fillTerritoryCombo(const QVariant &lng, QComboBox *combo)
{
combo->clear();
QLocale::Language lang = QLocale::Language(lng.toInt());
if (lang != QLocale::C) {
- for (QLocale::Country cntr : QLocale::countriesForLanguage(lang)) {
- QString country = QLocale::countryToString(cntr);
- auto loc = QLocale(lang, cntr);
+ const auto matches = QLocale::matchingLocales(lang, QLocale::AnyScript,
+ QLocale::AnyTerritory);
+ for (const auto &loc : matches) {
+ QString name = QLocale::territoryToString(loc.territory());
if (loc.language() != QLocale::English) {
- QString ncn = loc.nativeCountryName();
- if (!ncn.isEmpty())
- country = TranslationSettingsDialog::tr("%1 (%2)").arg(country, ncn);
+ QString endonym = loc.nativeTerritoryName();
+ if (!endonym.isEmpty())
+ name = TranslationSettingsDialog::tr("%1 (%2)").arg(name, endonym);
}
- combo->addItem(country, QVariant(cntr));
+ combo->addItem(name, QVariant(loc.territory()));
}
combo->model()->sort(0, Qt::AscendingOrder);
}
- combo->insertItem(0, TranslationSettingsDialog::tr("Any Country"), QVariant(QLocale::AnyCountry));
+ combo->insertItem(0, TranslationSettingsDialog::tr("Any Territory"),
+ QVariant(QLocale::AnyTerritory));
combo->setCurrentIndex(0);
}
void TranslationSettingsDialog::on_srcCbLanguageList_currentIndexChanged(int idx)
{
- fillCountryCombo(m_ui.srcCbLanguageList->itemData(idx), m_ui.srcCbCountryList);
+ fillTerritoryCombo(m_ui.srcCbLanguageList->itemData(idx), m_ui.srcCbCountryList);
}
void TranslationSettingsDialog::on_tgtCbLanguageList_currentIndexChanged(int idx)
{
- fillCountryCombo(m_ui.tgtCbLanguageList->itemData(idx), m_ui.tgtCbCountryList);
+ fillTerritoryCombo(m_ui.tgtCbLanguageList->itemData(idx), m_ui.tgtCbCountryList);
}
void TranslationSettingsDialog::on_buttonBox_accepted()
@@ -113,7 +92,7 @@ void TranslationSettingsDialog::on_buttonBox_accepted()
itemindex = m_ui.tgtCbCountryList->currentIndex();
var = m_ui.tgtCbCountryList->itemData(itemindex);
- QLocale::Country country = QLocale::Country(var.toInt());
+ QLocale::Territory territory = QLocale::Territory(var.toInt());
itemindex = m_ui.srcCbLanguageList->currentIndex();
var = m_ui.srcCbLanguageList->itemData(itemindex);
@@ -121,14 +100,14 @@ void TranslationSettingsDialog::on_buttonBox_accepted()
itemindex = m_ui.srcCbCountryList->currentIndex();
var = m_ui.srcCbCountryList->itemData(itemindex);
- QLocale::Country country2 = QLocale::Country(var.toInt());
+ QLocale::Territory territory2 = QLocale::Territory(var.toInt());
if (m_phraseBook) {
- m_phraseBook->setLanguageAndCountry(lang, country);
- m_phraseBook->setSourceLanguageAndCountry(lang2, country2);
+ m_phraseBook->setLanguageAndTerritory(lang, territory);
+ m_phraseBook->setSourceLanguageAndTerritory(lang2, territory2);
} else {
- m_dataModel->setLanguageAndCountry(lang, country);
- m_dataModel->setSourceLanguageAndCountry(lang2, country2);
+ m_dataModel->setLanguageAndTerritory(lang, territory);
+ m_dataModel->setSourceLanguageAndTerritory(lang2, territory2);
}
accept();
@@ -137,30 +116,30 @@ void TranslationSettingsDialog::on_buttonBox_accepted()
void TranslationSettingsDialog::showEvent(QShowEvent *)
{
QLocale::Language lang, lang2;
- QLocale::Country country, country2;
+ QLocale::Territory territory, territory2;
if (m_phraseBook) {
lang = m_phraseBook->language();
- country = m_phraseBook->country();
+ territory = m_phraseBook->territory();
lang2 = m_phraseBook->sourceLanguage();
- country2 = m_phraseBook->sourceCountry();
+ territory2 = m_phraseBook->sourceTerritory();
} else {
lang = m_dataModel->language();
- country = m_dataModel->country();
+ territory = m_dataModel->territory();
lang2 = m_dataModel->sourceLanguage();
- country2 = m_dataModel->sourceCountry();
+ territory2 = m_dataModel->sourceTerritory();
}
int itemindex = m_ui.tgtCbLanguageList->findData(QVariant(int(lang)));
m_ui.tgtCbLanguageList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
- itemindex = m_ui.tgtCbCountryList->findData(QVariant(int(country)));
+ itemindex = m_ui.tgtCbCountryList->findData(QVariant(int(territory)));
m_ui.tgtCbCountryList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
itemindex = m_ui.srcCbLanguageList->findData(QVariant(int(lang2)));
m_ui.srcCbLanguageList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
- itemindex = m_ui.srcCbCountryList->findData(QVariant(int(country2)));
+ itemindex = m_ui.srcCbCountryList->findData(QVariant(int(territory2)));
m_ui.srcCbCountryList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
}