1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #6258

powerjungle (1):
      fix(ui): system translation not being updated
This commit is contained in:
sudden6 2020-11-25 00:12:29 +01:00
commit ff1ab07a21
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 20 additions and 11 deletions

View File

@ -28,7 +28,8 @@
#include <QTranslator>
#include <algorithm>
QTranslator* Translator::translator{nullptr};
QTranslator* Translator::core_translator{nullptr};
QTranslator* Translator::app_translator{nullptr};
QVector<Translator::Callback> Translator::callbacks;
QMutex Translator::lock;
@ -39,31 +40,38 @@ void Translator::translate(const QString& localeName)
{
QMutexLocker locker{&lock};
if (!translator)
translator = new QTranslator();
if (!core_translator)
core_translator = new QTranslator();
if (!app_translator)
app_translator = new QTranslator();
// Remove old translations
QCoreApplication::removeTranslator(core_translator);
QApplication::removeTranslator(app_translator);
// Load translations
QCoreApplication::removeTranslator(translator);
QString locale = localeName.isEmpty() ? QLocale::system().name().section('_', 0, 0) : localeName;
if (locale != "en") {
if (translator->load(locale, ":translations/")) {
if (core_translator->load(locale, ":translations/")) {
qDebug() << "Loaded translation" << locale;
// system menu translation
QTranslator* qtTranslator = new QTranslator();
// System menu translation
QString s_locale = "qt_" + locale;
QString location = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
if (qtTranslator->load(s_locale, location)) {
QApplication::installTranslator(qtTranslator);
if (app_translator->load(s_locale, location)) {
QApplication::installTranslator(app_translator);
qDebug() << "System translation loaded" << locale;
} else {
qDebug() << "System translation not loaded" << locale;
}
// Application translation
QCoreApplication::installTranslator(core_translator);
} else {
qDebug() << "Error loading translation" << locale;
}
QCoreApplication::installTranslator(translator);
}
// After the language is changed from RTL to LTR, the layout direction isn't

View File

@ -38,5 +38,6 @@ private:
using Callback = QPair<void*, std::function<void()>>;
static QVector<Callback> callbacks;
static QMutex lock;
static QTranslator* translator;
static QTranslator* core_translator;
static QTranslator* app_translator;
};