35 const QString configPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
36 const QDir configDir(configPath);
37 if (!configDir.exists()) {
38 configDir.mkpath(QStringLiteral(
"."));
40 return QSettingsPtr(
new QSettings(configPath + QStringLiteral(
"/klanguageoverridesrc"), QSettings::IniFormat));
139 setWindowTitle(i18n(
"Switch Application Language"));
141 QVBoxLayout *topLayout =
new QVBoxLayout(
this);
143 QLabel *label =
new QLabel(i18n(
"Please choose the language which should be used for this application:"),
this);
144 topLayout->addWidget(label);
146 QHBoxLayout *languageHorizontalLayout =
new QHBoxLayout();
147 topLayout->addLayout(languageHorizontalLayout);
151 languageHorizontalLayout->addStretch();
155 int count = defaultLanguages.count();
156 for (
int i = 0; i < count; ++i) {
157 QString language = defaultLanguages[i];
158 bool primaryLanguage = (i == 0);
167 QHBoxLayout *addButtonHorizontalLayout =
new QHBoxLayout();
168 topLayout->addLayout(addButtonHorizontalLayout);
170 QPushButton *addLangButton =
new QPushButton(i18n(
"Add Fallback Language"),
this);
171 addLangButton->setToolTip(i18n(
"Adds one more language which will be used if other translations do not contain a proper translation."));
173 addButtonHorizontalLayout->addWidget(addLangButton);
174 addButtonHorizontalLayout->addStretch();
176 topLayout->addStretch(10);
178 QDialogButtonBox *buttonBox =
new QDialogButtonBox(
this);
179 buttonBox->setStandardButtons(QDialogButtonBox::Ok
180 | QDialogButtonBox::Cancel
181 | QDialogButtonBox::RestoreDefaults);
182 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
183 KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
184 KGuiItem::assign(buttonBox->button(QDialogButtonBox::RestoreDefaults), KStandardGuiItem::defaults());
186 topLayout->addWidget(buttonBox);
188 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(
slotOk()));
189 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
190 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
191 connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), SIGNAL(clicked()),
208 QObject
const *signalSender = sender();
210 qCritical() <<
"KisKSwitchLanguageDialog::removeButtonClicked() called directly, not using signal" << Qt::endl;
214 QPushButton *removeButton =
const_cast<QPushButton *
>(::qobject_cast<const QPushButton *>(signalSender));
216 qCritical() <<
"KisKSwitchLanguageDialog::removeButtonClicked() called from something else than QPushButton" << Qt::endl;
220 QMap<QPushButton *, LanguageRowData>::iterator it =
d->
languageRows.find(removeButton);
222 qCritical() <<
"KisKSwitchLanguageDialog::removeButtonClicked called from unknown QPushButton" << Qt::endl;
230 languageRowData.
label->deleteLater();
300 QLocale defaultLocale;
301 QLocale cLocale(QLocale::C);
302 QLocale::setDefault(cLocale);
303 QSet<QString> insertedLanguages;
305 const QList<QLocale> allLocales = QLocale::matchingLocales(QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry);
306 Q_FOREACH (
const QLocale &l, allLocales) {
307 QString languageCode = l.name();
309 const QString nativeName = l.nativeLanguageName();
313 const QString languageName = nativeName.isEmpty() ? QLocale::languageToString(l.language()) : nativeName;
314 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
322 if (l.language() != QLocale::English && l.language() != QLocale::Chinese && languageCode.contains(
'_')) {
323 QString countryName = l.nativeCountryName();
325 if (countryName.isEmpty()) {
326 countryName = QLocale::countryToString(l.country());
329 displayName = languageName %
" (" % countryName %
")";
331 displayName = languageName;
333 button->insertLanguage(languageCode, displayName);
334 insertedLanguages << languageCode;
336 if (!insertedLanguages.contains(languageCode) && KLocalizedString::isApplicationTranslatedInto(languageCode)) {
337 button->insertLanguage(languageCode, languageName);
338 insertedLanguages << languageCode;
344 QLocale::setDefault(defaultLocale);
352 if (!languageCode.isEmpty()) {
353 languagesList = QString::fromLatin1(languageCode).split(QLatin1Char(
':'));
355 if (languagesList.isEmpty()) {
357 languagesList = l.uiLanguages();
360 for (
int i = 0; i < languagesList.count(); ++i) {
361 languagesList[i].replace(QLatin1String(
"-"), QLatin1String(
"_"));
365 for (
int i = 0; i < languagesList.count();) {
366 QString languageCode = languagesList[i];
367 if (!KLocalizedString::isApplicationTranslatedInto(languageCode)) {
369 if (KLocalizedString::isApplicationTranslatedInto(languageCode)) {
370 languagesList[i] = languageCode;
375 languagesList.removeAt(i);
381 return languagesList;
386 QString labelText = primaryLanguage ? i18n(
"Primary language:") : i18n(
"Fallback language:");
396 SIGNAL(activated(QString)),
398 SLOT(languageOnButtonChanged(QString))
402 QPushButton *removeButton = 0;
404 if (!primaryLanguage) {
405 removeButton =
new QPushButton(i18n(
"Remove"),
p);
411 SLOT(removeButtonClicked())
415 languageButton->setToolTip(primaryLanguage
416 ? i18n(
"This is the main application language which will be used first, before any other languages.")
417 : i18n(
"This is the language which will be used if any previous languages do not contain a proper translation."));
421 QLabel *languageLabel =
new QLabel(labelText,
p);
422 languagesLayout->addWidget(languageLabel, numRows + 1, 1, Qt::AlignLeft);
423 languagesLayout->addWidget(languageButton, numRows + 1, 2, Qt::AlignLeft);
425 if (!primaryLanguage) {
426 languagesLayout->addWidget(removeButton, numRows + 1, 3, Qt::AlignLeft);
427 languageRowData.
setRowWidgets(languageLabel, languageButton, removeButton);
428 removeButton->show();
434 languageButton->show();
435 languageLabel->show();