9#include <QtCore/QLocale>
18 for (
int i = QLocale::C + 1; i < QLocale::LastLanguage; ++i) {
19 const auto language = QLocale::Language(i);
20 QString lang = QLocale::languageToString(language);
21 const auto loc = QLocale(language);
25 if (loc.language() == language && language != QLocale::English) {
26 const QString native = loc.nativeLanguageName();
27 if (!native.isEmpty())
28 lang = tr(
"%1 (%2)").arg(lang, native);
30 m_ui.srcCbLanguageList->addItem(lang, QVariant(i));
32 m_ui.srcCbLanguageList->model()->sort(0, Qt::AscendingOrder);
33 m_ui.srcCbLanguageList->insertItem(0, QLatin1String(
"POSIX"), QVariant(QLocale::C));
35 m_ui.tgtCbLanguageList->setModel(m_ui.srcCbLanguageList->model());
40 m_dataModel = dataModel;
42 QString fn = QFileInfo(dataModel->srcFileName()).baseName();
43 setWindowTitle(tr(
"Settings for '%1' - Qt Linguist").arg(fn));
48 m_phraseBook = phraseBook;
50 QString fn = QFileInfo(phraseBook->fileName()).baseName();
51 setWindowTitle(tr(
"Settings for '%1' - Qt Linguist").arg(fn));
57 QLocale::Language lang = QLocale::Language(lng.toInt());
58 if (lang != QLocale::C) {
59 const auto matches = QLocale::matchingLocales(lang, QLocale::AnyScript,
60 QLocale::AnyTerritory);
61 for (
const auto &loc : matches) {
62 QString name = QLocale::territoryToString(loc.territory());
63 if (loc.language() != QLocale::English) {
64 QString endonym = loc.nativeTerritoryName();
65 if (!endonym.isEmpty())
66 name = TranslationSettingsDialog::tr(
"%1 (%2)").arg(name, endonym);
68 combo->addItem(name, QVariant(loc.territory()));
70 combo->model()->sort(0, Qt::AscendingOrder);
72 combo->insertItem(0, TranslationSettingsDialog::tr(
"Any Territory"),
73 QVariant(QLocale::AnyTerritory));
74 combo->setCurrentIndex(0);
79 fillTerritoryCombo(m_ui.srcCbLanguageList->itemData(idx), m_ui.srcCbCountryList);
84 fillTerritoryCombo(m_ui.tgtCbLanguageList->itemData(idx), m_ui.tgtCbCountryList);
89 int itemindex = m_ui.tgtCbLanguageList->currentIndex();
90 QVariant var = m_ui.tgtCbLanguageList->itemData(itemindex);
91 QLocale::Language lang = QLocale::Language(var.toInt());
93 itemindex = m_ui.tgtCbCountryList->currentIndex();
94 var = m_ui.tgtCbCountryList->itemData(itemindex);
95 QLocale::Territory territory = QLocale::Territory(var.toInt());
97 itemindex = m_ui.srcCbLanguageList->currentIndex();
98 var = m_ui.srcCbLanguageList->itemData(itemindex);
99 QLocale::Language lang2 = QLocale::Language(var.toInt());
101 itemindex = m_ui.srcCbCountryList->currentIndex();
102 var = m_ui.srcCbCountryList->itemData(itemindex);
103 QLocale::Territory territory2 = QLocale::Territory(var.toInt());
106 m_phraseBook->setLanguageAndTerritory(lang, territory);
107 m_phraseBook->setSourceLanguageAndTerritory(lang2, territory2);
109 m_dataModel->setLanguageAndTerritory(lang, territory);
110 m_dataModel->setSourceLanguageAndTerritory(lang2, territory2);
118 QLocale::Language lang, lang2;
119 QLocale::Territory territory, territory2;
122 lang = m_phraseBook->language();
123 territory = m_phraseBook->territory();
124 lang2 = m_phraseBook->sourceLanguage();
125 territory2 = m_phraseBook->sourceTerritory();
127 lang = m_dataModel->language();
128 territory = m_dataModel->territory();
129 lang2 = m_dataModel->sourceLanguage();
130 territory2 = m_dataModel->sourceTerritory();
133 int itemindex = m_ui.tgtCbLanguageList->findData(QVariant(
int(lang)));
134 m_ui.tgtCbLanguageList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
136 itemindex = m_ui.tgtCbCountryList->findData(QVariant(
int(territory)));
137 m_ui.tgtCbCountryList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
139 itemindex = m_ui.srcCbLanguageList->findData(QVariant(
int(lang2)));
140 m_ui.srcCbLanguageList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
142 itemindex = m_ui.srcCbCountryList->findData(QVariant(
int(territory2)));
143 m_ui.srcCbCountryList->setCurrentIndex(itemindex == -1 ? 0 : itemindex);
void showEvent(QShowEvent *e) override
\reimp
void setDataModel(DataModel *model)
void setPhraseBook(PhraseBook *phraseBook)
Combined button and popup list for selecting options.
static void fillTerritoryCombo(const QVariant &lng, QComboBox *combo)