mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-01-24 15:18:07 +00:00
feat(app/App): use own translator
This commit is contained in:
parent
85b3c81648
commit
46a1bf4fff
6 changed files with 61 additions and 28 deletions
|
|
@ -32,6 +32,7 @@ list(APPEND LIBS "${CMAKE_SOURCE_DIR}/../OUTPUT/desktop/lib64/liblinphone++.so")
|
|||
set(SOURCES
|
||||
src/app/App.cpp
|
||||
src/app/Database.cpp
|
||||
src/app/DefaultTranslator.cpp
|
||||
src/app/Logger.cpp
|
||||
src/components/chat/ChatModel.cpp
|
||||
src/components/chat/ChatProxyModel.cpp
|
||||
|
|
@ -51,6 +52,7 @@ set(SOURCES
|
|||
set(HEADERS
|
||||
src/app/App.hpp
|
||||
src/app/Database.hpp
|
||||
src/app/DefaultTranslator.hpp
|
||||
src/app/Logger.hpp
|
||||
src/components/chat/ChatModel.hpp
|
||||
src/components/chat/ChatProxyModel.hpp
|
||||
|
|
|
|||
|
|
@ -178,41 +178,29 @@
|
|||
<source>incomingCall</source>
|
||||
<translation>Incoming call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>hangup</source>
|
||||
<translation type="vanished">End call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>lostIncomingCall</source>
|
||||
<translation type="vanished">Lost incoming call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>lostOutgoingCall</source>
|
||||
<translation type="vanished">Lost outgoing call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>outgoingCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Outgoing call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>declinedIncomingCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Declined incoming call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>declinedOutgoingCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Declined outgoing call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>endedCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Ended call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>missedIncomingCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Missed incoming call</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>missedOutgoingCall</source>
|
||||
<translation type="unfinished"></translation>
|
||||
<translation>Missed outgoing call</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
|
|
|
|||
|
|
@ -29,15 +29,18 @@ App *App::m_instance = nullptr;
|
|||
App::App (int &argc, char **argv) : QApplication(argc, argv) {
|
||||
QString current_locale = QLocale::system().name();
|
||||
|
||||
// Try to use default locale. Otherwise use english.
|
||||
if (m_translator.load(QString(LANGUAGES_PATH) + current_locale)) {
|
||||
installTranslator(&m_translator);
|
||||
if (m_english_translator.load(LANGUAGES_PATH "en"))
|
||||
installTranslator(&m_english_translator);
|
||||
else
|
||||
qWarning("Unable to install english translator.");
|
||||
|
||||
// Try to use default locale.
|
||||
if (m_default_translator.load(QString(LANGUAGES_PATH) + current_locale)) {
|
||||
installTranslator(&m_default_translator);
|
||||
m_locale = current_locale;
|
||||
} else if (m_translator.load(LANGUAGES_PATH "en")) {
|
||||
installTranslator(&m_translator);
|
||||
} else {
|
||||
qFatal("No translation found.");
|
||||
}
|
||||
} else
|
||||
qWarning() << QStringLiteral("Unable to found translations for locale: %1.")
|
||||
.arg(current_locale);
|
||||
|
||||
setWindowIcon(QIcon(WINDOW_ICON_PATH));
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlFileSelector>
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QTranslator>
|
||||
|
||||
#include "DefaultTranslator.hpp"
|
||||
|
||||
class Notifier;
|
||||
|
||||
|
|
@ -47,7 +48,9 @@ private:
|
|||
QQmlApplicationEngine m_engine;
|
||||
QQmlFileSelector *m_file_selector = nullptr;
|
||||
QSystemTrayIcon *m_system_tray_icon = nullptr;
|
||||
QTranslator m_translator;
|
||||
|
||||
DefaultTranslator m_default_translator;
|
||||
QTranslator m_english_translator;
|
||||
|
||||
Notifier *m_notifier = nullptr;
|
||||
QString m_locale = "en";
|
||||
|
|
|
|||
20
tests/src/app/DefaultTranslator.cpp
Normal file
20
tests/src/app/DefaultTranslator.cpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#include <QtDebug>
|
||||
|
||||
#include "DefaultTranslator.hpp"
|
||||
|
||||
// ===================================================================
|
||||
|
||||
QString DefaultTranslator::translate (
|
||||
const char *context,
|
||||
const char *source_text,
|
||||
const char *disambiguation,
|
||||
int n
|
||||
) const {
|
||||
QString translation = QTranslator::translate(context, source_text, disambiguation, n);
|
||||
|
||||
if (translation.length() == 0)
|
||||
qWarning() << QStringLiteral("Unable to found a translation. (context=%1, label=%2)")
|
||||
.arg(context).arg(source_text);
|
||||
|
||||
return translation;
|
||||
}
|
||||
17
tests/src/app/DefaultTranslator.hpp
Normal file
17
tests/src/app/DefaultTranslator.hpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef DEFAULT_TRANSLATOR_H_
|
||||
#define DEFAULT_TRANSLATOR_H_
|
||||
|
||||
#include <QTranslator>
|
||||
|
||||
// ===================================================================
|
||||
|
||||
class DefaultTranslator : public QTranslator {
|
||||
QString translate (
|
||||
const char *context,
|
||||
const char *source_text,
|
||||
const char *disambiguation = Q_NULLPTR,
|
||||
int n = -1
|
||||
) const override;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue