48 const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
49 const QDir configDir(configPath);
50 if (!configDir.exists()) {
51 configDir.mkpath(QStringLiteral(
"."));
53 return QSettingsPtr(
new QSettings(configPath + QStringLiteral(
"/klanguageoverridesrc"), QSettings::IniFormat));
152 setWindowTitle(i18n(
"Switch Application Language"));
154 QVBoxLayout *topLayout =
new QVBoxLayout(
this);
156 QLabel *label =
new QLabel(i18n(
"Please choose the language which should be used for this application:"),
this);
157 topLayout->addWidget(label);
159 QHBoxLayout *languageHorizontalLayout =
new QHBoxLayout();
160 topLayout->addLayout(languageHorizontalLayout);
164 languageHorizontalLayout->addStretch();
168 int count = defaultLanguages.count();
173 for (
int i = 0; i < count; ++i) {
174 QString language = defaultLanguages[i];
175 bool primaryLanguage = (i == 0);
185 QHBoxLayout *addButtonHorizontalLayout =
new QHBoxLayout();
186 topLayout->addLayout(addButtonHorizontalLayout);
188 QPushButton *addLangButton =
new QPushButton(i18n(
"Add Fallback Language"),
this);
189 addLangButton->setToolTip(i18n(
"Adds one more language which will be used if other translations do not contain a proper translation."));
191 addButtonHorizontalLayout->addWidget(addLangButton);
192 addButtonHorizontalLayout->addStretch();
195 topLayout->addStretch(10);
197 QDialogButtonBox *buttonBox =
new QDialogButtonBox(
this);
198 buttonBox->setStandardButtons(QDialogButtonBox::Ok
199 | QDialogButtonBox::Cancel
200 | QDialogButtonBox::RestoreDefaults);
201 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
202 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
203 KGuiItem::assign(buttonBox->button(QDialogButtonBox::RestoreDefaults), KStandardGuiItem::defaults());
205 topLayout->addWidget(buttonBox);
207 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(
slotOk()));
208 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
209 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
210 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()),
227 QObject
const *signalSender = sender();
229 qCritical() <<
"KisKSwitchLanguageDialog::removeButtonClicked() called directly, not using signal" << Qt::endl;
233 QPushButton *removeButton =
const_cast<QPushButton *
>(::qobject_cast<const QPushButton *>(signalSender));
235 qCritical() <<
"KisKSwitchLanguageDialog::removeButtonClicked() called from something else than QPushButton" << Qt::endl;
239 QMap<QPushButton *, LanguageRowData>::iterator it =
d->
languageRows.find(removeButton);
241 qCritical() <<
"KisKSwitchLanguageDialog::removeButtonClicked called from unknown QPushButton" << Qt::endl;
249 languageRowData.
label->deleteLater();
319 QLocale defaultLocale;
320 QLocale cLocale(QLocale::C);
321 QLocale::setDefault(cLocale);
322 QSet<QString> insertedLanguages;
324 const QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
325 Q_FOREACH (
const QLocale &l, allLocales) {
326 QString languageCode = l.name();
328 const QString nativeName = l.nativeLanguageName();
332 const QString languageName = nativeName.isEmpty() ? QLocale::languageToString(l.language()) : nativeName;
333 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
341#if QT_VERSION < QT_VERSION_CHECK(6, 2, 0)
342 if (l.language() != QLocale::English && l.language() != QLocale::Chinese && languageCode.contains(
'_')) {
343 QString territoryName = l.nativeCountryName();
345 if (territoryName.isEmpty()) {
346 territoryName = QLocale::countryToString(l.country());
348 if (l.language() != QLocale::English && l.language() != QLocale::Chinese && languageCode.contains(
'_')) {
349 QString territoryName = l.nativeTerritoryName();
351 if (territoryName.isEmpty()) {
352 territoryName = QLocale::territoryToString(l.territory());
356 displayName = languageName %
" (" % territoryName %
")";
358 displayName = languageName;
360 button->insertLanguage(languageCode, displayName);
361 insertedLanguages << languageCode;
363 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
364 button->insertLanguage(languageCode, languageName);
365 insertedLanguages << languageCode;
371 QLocale::setDefault(defaultLocale);
379 if (!languageCode.isEmpty()) {
380 languagesList = QString::fromLatin1(languageCode).split(QLatin1Char(
':'));
382 if (languagesList.isEmpty()) {
384 languagesList = l.uiLanguages();
387 for (
int i = 0; i < languagesList.count(); ++i) {
388 languagesList[i].replace(QLatin1String(
"-"), QLatin1String(
"_"));
392 for (
int i = 0; i < languagesList.count();) {
393 QString languageCode = languagesList[i];
394 if (!KLocalizedString::isApplicationTranslatedInto(languageCode)) {
396 if (KLocalizedString::isApplicationTranslatedInto(languageCode)) {
397 languagesList[i] = languageCode;
402 languagesList.removeAt(i);
408 return languagesList;
413 QString labelText = primaryLanguage ? i18n(
"Primary language:") : i18n(
"Fallback language:");
423 SIGNAL(activated(QString)),
425 SLOT(languageOnButtonChanged(QString))
429 QPushButton *removeButton = 0;
431 if (!primaryLanguage) {
432 removeButton =
new QPushButton(i18n(
"Remove"),
p);
438 SLOT(removeButtonClicked())
442 languageButton->setToolTip(primaryLanguage
443 ? i18n(
"This is the main application language which will be used first, before any other languages.")
444 : i18n(
"This is the language which will be used if any previous languages do not contain a proper translation."));
448 QLabel *languageLabel =
new QLabel(labelText,
p);
449 languagesLayout->addWidget(languageLabel, numRows + 1, 1, Qt::AlignLeft);
450 languagesLayout->addWidget(languageButton, numRows + 1, 2, Qt::AlignLeft);
452 if (!primaryLanguage) {
453 languagesLayout->addWidget(removeButton, numRows + 1, 3, Qt::AlignLeft);
454 languageRowData.
setRowWidgets(languageLabel, languageButton, removeButton);
455 removeButton->show();
461 languageButton->show();
462 languageLabel->show();