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/camerasource.cpp \
|
||||||
src/video/corevideosource.cpp \
|
src/video/corevideosource.cpp \
|
||||||
src/core/toxid.cpp \
|
src/core/toxid.cpp \
|
||||||
src/profile.cpp
|
src/profile.cpp \
|
||||||
|
src/translator.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/audio.h \
|
src/audio.h \
|
||||||
|
@ -505,4 +506,5 @@ HEADERS += \
|
||||||
src/video/corevideosource.h \
|
src/video/corevideosource.h \
|
||||||
src/video/videomode.h \
|
src/video/videomode.h \
|
||||||
src/core/toxid.h \
|
src/core/toxid.h \
|
||||||
src/profile.h
|
src/profile.h \
|
||||||
|
src/translator.h
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "src/profile.h"
|
#include "src/profile.h"
|
||||||
#include "src/profilelocker.h"
|
#include "src/profilelocker.h"
|
||||||
#include "src/widget/loginscreen.h"
|
#include "src/widget/loginscreen.h"
|
||||||
|
#include "src/translator.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
@ -98,6 +99,8 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
qsrand(time(0));
|
qsrand(time(0));
|
||||||
|
|
||||||
|
Translator::translate();
|
||||||
|
|
||||||
// Process arguments
|
// Process arguments
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("qTox, version: " + QString(GIT_VERSION) + "\nBuilt: " + __TIME__ + " " + __DATE__);
|
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/misc/style.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
#include "src/profile.h"
|
#include "src/profile.h"
|
||||||
|
#include "src/translator.h"
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
|
@ -211,7 +212,7 @@ void GeneralForm::onEnableIPv6Updated()
|
||||||
void GeneralForm::onTranslationUpdated()
|
void GeneralForm::onTranslationUpdated()
|
||||||
{
|
{
|
||||||
Settings::getInstance().setTranslation(locales[bodyUI->transComboBox->currentIndex()]);
|
Settings::getInstance().setTranslation(locales[bodyUI->transComboBox->currentIndex()]);
|
||||||
Widget::getInstance()->setTranslation();
|
Translator::translate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GeneralForm::onAutorunUpdated()
|
void GeneralForm::onAutorunUpdated()
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
#include "src/widget/gui.h"
|
#include "src/widget/gui.h"
|
||||||
#include "src/offlinemsgengine.h"
|
#include "src/offlinemsgengine.h"
|
||||||
|
#include "src/translator.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
@ -50,14 +51,12 @@
|
||||||
#include <QShortcut>
|
#include <QShortcut>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
#include <QTranslator>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QLibraryInfo>
|
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
|
@ -85,8 +84,7 @@ Widget::Widget(QWidget *parent)
|
||||||
eventIcon(false)
|
eventIcon(false)
|
||||||
{
|
{
|
||||||
installEventFilter(this);
|
installEventFilter(this);
|
||||||
translator = new QTranslator;
|
Translator::translate();
|
||||||
setTranslation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::init()
|
void Widget::init()
|
||||||
|
@ -228,41 +226,6 @@ void Widget::init()
|
||||||
show();
|
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)
|
bool Widget::eventFilter(QObject *obj, QEvent *event)
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::WindowStateChange && obj != NULL)
|
if (event->type() == QEvent::WindowStateChange && obj != NULL)
|
||||||
|
@ -327,7 +290,6 @@ Widget::~Widget()
|
||||||
GroupList::clear();
|
GroupList::clear();
|
||||||
delete trayMenu;
|
delete trayMenu;
|
||||||
delete ui;
|
delete ui;
|
||||||
delete translator;
|
|
||||||
instance = nullptr;
|
instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,6 @@ class Camera;
|
||||||
class FriendListWidget;
|
class FriendListWidget;
|
||||||
class MaskablePixmapWidget;
|
class MaskablePixmapWidget;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class QTranslator;
|
|
||||||
class SystemTrayIcon;
|
class SystemTrayIcon;
|
||||||
|
|
||||||
class Widget : public QMainWindow
|
class Widget : public QMainWindow
|
||||||
|
@ -70,7 +69,6 @@ public:
|
||||||
void newMessageAlert(GenericChatroomWidget* chat);
|
void newMessageAlert(GenericChatroomWidget* chat);
|
||||||
bool isFriendWidgetCurActiveWidget(Friend* f);
|
bool isFriendWidgetCurActiveWidget(Friend* f);
|
||||||
bool getIsWindowMinimized();
|
bool getIsWindowMinimized();
|
||||||
void setTranslation();
|
|
||||||
void updateIcons();
|
void updateIcons();
|
||||||
void clearContactsList();
|
void clearContactsList();
|
||||||
~Widget();
|
~Widget();
|
||||||
|
@ -197,7 +195,6 @@ private:
|
||||||
bool autoAwayActive = false;
|
bool autoAwayActive = false;
|
||||||
Status beforeDisconnect = Status::Offline;
|
Status beforeDisconnect = Status::Offline;
|
||||||
QTimer *timer, *offlineMsgTimer;
|
QTimer *timer, *offlineMsgTimer;
|
||||||
QTranslator* translator;
|
|
||||||
QRegExp nameMention, sanitizedNameMention;
|
QRegExp nameMention, sanitizedNameMention;
|
||||||
bool eventFlag;
|
bool eventFlag;
|
||||||
bool eventIcon;
|
bool eventIcon;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user