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

fix(ui): system translation not being updated

This commit fixes an issue when switching from any language back to English,
the system translations remain to be the last language even if the application
translations have switched back to English.
This commit is contained in:
powerjungle 2020-11-22 16:27:09 +02:00
parent 425e3f6518
commit 6527fd4fca
No known key found for this signature in database
GPG Key ID: 190C37B0F8665DA8
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;
};