mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Translate all GUI, not just Widget
This commit is contained in:
parent
fc647761d1
commit
6bf0317e3e
6
qtox.pro
6
qtox.pro
|
@ -471,7 +471,8 @@ SOURCES += \
|
|||
src/video/camerasource.cpp \
|
||||
src/video/corevideosource.cpp \
|
||||
src/core/toxid.cpp \
|
||||
src/profile.cpp
|
||||
src/profile.cpp \
|
||||
src/translator.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/audio.h \
|
||||
|
@ -505,4 +506,5 @@ HEADERS += \
|
|||
src/video/corevideosource.h \
|
||||
src/video/videomode.h \
|
||||
src/core/toxid.h \
|
||||
src/profile.h
|
||||
src/profile.h \
|
||||
src/translator.h
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "src/profile.h"
|
||||
#include "src/profilelocker.h"
|
||||
#include "src/widget/loginscreen.h"
|
||||
#include "src/translator.h"
|
||||
#include <QApplication>
|
||||
#include <QCommandLineParser>
|
||||
#include <QDateTime>
|
||||
|
@ -98,6 +99,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
qsrand(time(0));
|
||||
|
||||
Translator::translate();
|
||||
|
||||
// Process arguments
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription("qTox, version: " + QString(GIT_VERSION) + "\nBuilt: " + __TIME__ + " " + __DATE__);
|
||||
|
|
48
src/translator.cpp
Normal file
48
src/translator.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include "translator.h"
|
||||
#include "src/misc/settings.h"
|
||||
#include <QApplication>
|
||||
#include <QString>
|
||||
#include <QLocale>
|
||||
#include <QTranslator>
|
||||
#include <QLibraryInfo>
|
||||
#include <QDebug>
|
||||
|
||||
QTranslator* Translator::translator{nullptr};
|
||||
|
||||
void Translator::translate()
|
||||
{
|
||||
if (!translator)
|
||||
translator = new QTranslator();
|
||||
|
||||
// Load translations
|
||||
QCoreApplication::removeTranslator(translator);
|
||||
QString locale;
|
||||
if ((locale = Settings::getInstance().getTranslation()).isEmpty())
|
||||
locale = QLocale::system().name().section('_', 0, 0);
|
||||
|
||||
if (locale == "en")
|
||||
return;
|
||||
|
||||
if (translator->load(locale, ":translations/"))
|
||||
{
|
||||
qDebug() << "Loaded translation" << locale;
|
||||
|
||||
// system menu translation
|
||||
QTranslator *qtTranslator = new QTranslator();
|
||||
QString s_locale = "qt_"+locale;
|
||||
if (qtTranslator->load(s_locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||
{
|
||||
QApplication::installTranslator(qtTranslator);
|
||||
qDebug() << "System translation loaded" << locale;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "System translation not loaded" << locale;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Error loading translation" << locale;
|
||||
}
|
||||
QCoreApplication::installTranslator(translator);
|
||||
}
|
16
src/translator.h
Normal file
16
src/translator.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef TRANSLATOR_H
|
||||
#define TRANSLATOR_H
|
||||
|
||||
class QTranslator;
|
||||
|
||||
class Translator
|
||||
{
|
||||
public:
|
||||
/// Loads the translations according to the settings or locale
|
||||
static void translate();
|
||||
|
||||
private:
|
||||
static QTranslator* translator;
|
||||
};
|
||||
|
||||
#endif // TRANSLATOR_H
|
|
@ -22,6 +22,7 @@
|
|||
#include "src/misc/style.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/profile.h"
|
||||
#include "src/translator.h"
|
||||
#include <QMessageBox>
|
||||
#include <QStyleFactory>
|
||||
#include <QTime>
|
||||
|
@ -211,7 +212,7 @@ void GeneralForm::onEnableIPv6Updated()
|
|||
void GeneralForm::onTranslationUpdated()
|
||||
{
|
||||
Settings::getInstance().setTranslation(locales[bodyUI->transComboBox->currentIndex()]);
|
||||
Widget::getInstance()->setTranslation();
|
||||
Translator::translate();
|
||||
}
|
||||
|
||||
void GeneralForm::onAutorunUpdated()
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include "src/nexus.h"
|
||||
#include "src/widget/gui.h"
|
||||
#include "src/offlinemsgengine.h"
|
||||
#include "src/translator.h"
|
||||
#include <cassert>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
|
@ -50,14 +51,12 @@
|
|||
#include <QShortcut>
|
||||
#include <QTimer>
|
||||
#include <QStyleFactory>
|
||||
#include <QTranslator>
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QImageReader>
|
||||
#include <QList>
|
||||
#include <QDesktopServices>
|
||||
#include <QProcess>
|
||||
#include <QLibraryInfo>
|
||||
#include <tox/tox.h>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
|
@ -85,8 +84,7 @@ Widget::Widget(QWidget *parent)
|
|||
eventIcon(false)
|
||||
{
|
||||
installEventFilter(this);
|
||||
translator = new QTranslator;
|
||||
setTranslation();
|
||||
Translator::translate();
|
||||
}
|
||||
|
||||
void Widget::init()
|
||||
|
@ -228,41 +226,6 @@ void Widget::init()
|
|||
show();
|
||||
}
|
||||
|
||||
void Widget::setTranslation()
|
||||
{
|
||||
// Load translations
|
||||
QCoreApplication::removeTranslator(translator);
|
||||
QString locale;
|
||||
if ((locale = Settings::getInstance().getTranslation()).isEmpty())
|
||||
locale = QLocale::system().name().section('_', 0, 0);
|
||||
|
||||
if (locale == "en")
|
||||
return;
|
||||
|
||||
if (translator->load(locale, ":translations/"))
|
||||
{
|
||||
qDebug() << "Loaded translation" << locale;
|
||||
|
||||
// system menu translation
|
||||
QTranslator *qtTranslator = new QTranslator();
|
||||
QString s_locale = "qt_"+locale;
|
||||
if (qtTranslator->load(s_locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
|
||||
{
|
||||
QApplication::installTranslator(qtTranslator);
|
||||
qDebug() << "System translation loaded" << locale;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "System translation not loaded" << locale;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Error loading translation" << locale;
|
||||
}
|
||||
QCoreApplication::installTranslator(translator);
|
||||
}
|
||||
|
||||
bool Widget::eventFilter(QObject *obj, QEvent *event)
|
||||
{
|
||||
if (event->type() == QEvent::WindowStateChange && obj != NULL)
|
||||
|
@ -327,7 +290,6 @@ Widget::~Widget()
|
|||
GroupList::clear();
|
||||
delete trayMenu;
|
||||
delete ui;
|
||||
delete translator;
|
||||
instance = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ class Camera;
|
|||
class FriendListWidget;
|
||||
class MaskablePixmapWidget;
|
||||
class QTimer;
|
||||
class QTranslator;
|
||||
class SystemTrayIcon;
|
||||
|
||||
class Widget : public QMainWindow
|
||||
|
@ -70,7 +69,6 @@ public:
|
|||
void newMessageAlert(GenericChatroomWidget* chat);
|
||||
bool isFriendWidgetCurActiveWidget(Friend* f);
|
||||
bool getIsWindowMinimized();
|
||||
void setTranslation();
|
||||
void updateIcons();
|
||||
void clearContactsList();
|
||||
~Widget();
|
||||
|
@ -197,7 +195,6 @@ private:
|
|||
bool autoAwayActive = false;
|
||||
Status beforeDisconnect = Status::Offline;
|
||||
QTimer *timer, *offlineMsgTimer;
|
||||
QTranslator* translator;
|
||||
QRegExp nameMention, sanitizedNameMention;
|
||||
bool eventFlag;
|
||||
bool eventIcon;
|
||||
|
|
Loading…
Reference in New Issue
Block a user