commit 9c3fa37c FixBug #180395, 响应应用语言设置接口

This commit is contained in:
tanjing 2023-08-23 16:21:01 +08:00 committed by xibowen
parent 4ce8839047
commit f95e11fa3b
2 changed files with 40 additions and 19 deletions

View File

@ -72,25 +72,16 @@ KyNativeFileDialog::KyNativeFileDialog(QWidget *parent)
: QDialog(parent),
d_ptr(new KyNativeFileDialogPrivate)
{
const QString locale = QLocale::system().name();
QTranslator *translator = new QTranslator(this);
pDebug << "local: " << locale;
if (translator->load("/usr/share/qt5-ukui-platformtheme/qt5-ukui-platformtheme_" + QLocale::system().name())) {
pDebug << "Load translations file success!";
QApplication::installTranslator(translator);
} else {
pDebug << "Load translations file failed!";
}
QString locale = QLocale::system().name();
QTranslator *t = new QTranslator(this);
pDebug << "QTranslator t load" << t->load("/usr/share/libpeony-qt/libpeony-qt_"+QLocale::system().name());
QApplication::installTranslator(t);
QTranslator *t2 = new QTranslator(this);
pDebug << "QTranslator t2 load" << t2->load("/usr/share/peony-qt-desktop/peony-qt-desktop_"+QLocale::system().name());
QApplication::installTranslator(t2);
QTranslator *t3 = new QTranslator(this);
pDebug << "QTranslator t3 load" << t3->load("/usr/share/qt5/translations/qt_"+QLocale::system().name());
QApplication::installTranslator(t3);
if(qApp->property("Language").isValid())
{
QString language = qApp->property("Language").toString();
QFile file("/usr/share/qt5-ukui-platformtheme/qt5-ukui-platformtheme_" + language + ".qm");
if(file.exists())
locale = language;
}
installTranslate(locale);
mKyFileDialogUi = new Ui_KyFileDialog(this);
@ -2521,6 +2512,28 @@ void KyNativeFileDialog::updateSearchProgressBar()
// }
}
void KyNativeFileDialog::installTranslate(QString locale)
{
m_translator0 = new QTranslator(this);
pDebug << "local: " << locale;
if (m_translator0->load("/usr/share/qt5-ukui-platformtheme/qt5-ukui-platformtheme_" + locale)) {
pDebug << "Load translations file success!";
QApplication::installTranslator(m_translator0);
} else {
pDebug << "Load translations file failed!";
}
m_translator1 = new QTranslator(this);
pDebug << "QTranslator t load" << m_translator1->load("/usr/share/libpeony-qt/libpeony-qt_" + locale);
QApplication::installTranslator(m_translator1);
m_translator2 = new QTranslator(this);
pDebug << "QTranslator t2 load" << m_translator2->load("/usr/share/peony-qt-desktop/peony-qt-desktop_" + locale);
QApplication::installTranslator(m_translator2);
m_translator3 = new QTranslator(this);
pDebug << "QTranslator t3 load" << m_translator3->load("/usr/share/qt5/translations/qt_" + locale);
QApplication::installTranslator(m_translator3);
}
KyFileDialogHelper::KyFileDialogHelper() : QPlatformFileDialogHelper(), mKyFileDialog(new KyNativeFileDialog)
{
mKyFileDialog->setHelper(this);

View File

@ -30,6 +30,7 @@
#include <QCompleter>
#include <QListView>
#include <QStringListModel>
#include <QTranslator>
#include "qpa/qplatformdialoghelper.h"
#include <peony-qt/FMWindowIface.h>
@ -180,6 +181,8 @@ public:
QString copyEditText();
void installTranslate(QString local);
Q_SIGNALS:
void switchViewRequest(const QString &viewId);
@ -216,7 +219,6 @@ protected:
private:
Ui_KyFileDialog *mKyFileDialogUi = nullptr;
KyNativeFileDialog *mKyFileDialog = nullptr;
QScopedPointer<KyNativeFileDialogPrivate> d_ptr;
Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), KyNativeFileDialog)
void onAcceptButtonClicked();
@ -244,6 +246,12 @@ private:
QMap<int, QString> m_nameFilterMap;
QStringList m_uris_to_edit;
bool m_needSearch = false;
QTranslator *m_translator0 = nullptr;
QTranslator *m_translator1 = nullptr;
QTranslator *m_translator2 = nullptr;
QTranslator *m_translator3 = nullptr;
};
class KyFileDialogHelper : public QPlatformFileDialogHelper