Unverified Commit 083dcf0a authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #7518 from mavlink/audioLocalization

Handle text to speech locale
parents eee967c5 a9ff4d8d
...@@ -20,6 +20,11 @@ AudioOutput::AudioOutput(QGCApplication* app, QGCToolbox* toolbox) ...@@ -20,6 +20,11 @@ AudioOutput::AudioOutput(QGCApplication* app, QGCToolbox* toolbox)
: QGCTool(app, toolbox) : QGCTool(app, toolbox)
, _tts(new QTextToSpeech(this)) , _tts(new QTextToSpeech(this))
{ {
//-- Force TTS engine to English as all incoming messages from the autopilot
// are in English and not localized.
#ifdef Q_OS_LINUX
_tts->setLocale(QLocale("en_US"));
#endif
connect(_tts, &QTextToSpeech::stateChanged, this, &AudioOutput::_stateChanged); connect(_tts, &QTextToSpeech::stateChanged, this, &AudioOutput::_stateChanged);
} }
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "QGC.h" #include "QGC.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "AudioOutput.h"
#include "CmdLineOptParser.h" #include "CmdLineOptParser.h"
#include "UDPLink.h" #include "UDPLink.h"
#include "LinkManager.h" #include "LinkManager.h"
...@@ -351,74 +350,74 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) ...@@ -351,74 +350,74 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
void QGCApplication::setLanguage() void QGCApplication::setLanguage()
{ {
QLocale locale = QLocale::system(); _locale = QLocale::system();
qDebug() << "System reported locale:" << locale << locale.name(); qDebug() << "System reported locale:" << _locale << _locale.name();
int langID = toolbox()->settingsManager()->appSettings()->language()->rawValue().toInt(); int langID = toolbox()->settingsManager()->appSettings()->language()->rawValue().toInt();
//-- See App.SettinsGroup.json for index //-- See App.SettinsGroup.json for index
if(langID) { if(langID) {
switch(langID) { switch(langID) {
case 1: case 1:
locale = QLocale(QLocale::Bulgarian); _locale = QLocale(QLocale::Bulgarian);
break; break;
case 2: case 2:
locale = QLocale(QLocale::Chinese); _locale = QLocale(QLocale::Chinese);
break; break;
case 3: case 3:
locale = QLocale(QLocale::Dutch); _locale = QLocale(QLocale::Dutch);
break; break;
case 4: case 4:
locale = QLocale(QLocale::English); _locale = QLocale(QLocale::English);
break; break;
case 5: case 5:
locale = QLocale(QLocale::Finnish); _locale = QLocale(QLocale::Finnish);
break; break;
case 6: case 6:
locale = QLocale(QLocale::French); _locale = QLocale(QLocale::French);
break; break;
case 7: case 7:
locale = QLocale(QLocale::German); _locale = QLocale(QLocale::German);
break; break;
case 8: case 8:
locale = QLocale(QLocale::Greek); _locale = QLocale(QLocale::Greek);
break; break;
case 9: case 9:
locale = QLocale(QLocale::Hebrew); _locale = QLocale(QLocale::Hebrew);
break; break;
case 10: case 10:
locale = QLocale(QLocale::Italian); _locale = QLocale(QLocale::Italian);
break; break;
case 11: case 11:
locale = QLocale(QLocale::Japanese); _locale = QLocale(QLocale::Japanese);
break; break;
case 12: case 12:
locale = QLocale(QLocale::Korean); _locale = QLocale(QLocale::Korean);
break; break;
case 13: case 13:
locale = QLocale(QLocale::Norwegian); _locale = QLocale(QLocale::Norwegian);
break; break;
case 14: case 14:
locale = QLocale(QLocale::Polish); _locale = QLocale(QLocale::Polish);
break; break;
case 15: case 15:
locale = QLocale(QLocale::Portuguese); _locale = QLocale(QLocale::Portuguese);
break; break;
case 16: case 16:
locale = QLocale(QLocale::Russian); _locale = QLocale(QLocale::Russian);
break; break;
case 17: case 17:
locale = QLocale(QLocale::Spanish); _locale = QLocale(QLocale::Spanish);
break; break;
case 18: case 18:
locale = QLocale(QLocale::Swedish); _locale = QLocale(QLocale::Swedish);
break; break;
case 19: case 19:
locale = QLocale(QLocale::Turkish); _locale = QLocale(QLocale::Turkish);
break; break;
} }
} }
//-- We have specific fonts for Korean //-- We have specific fonts for Korean
if(locale == QLocale::Korean) { if(_locale == QLocale::Korean) {
qDebug() << "Loading Korean fonts" << locale.name(); qDebug() << "Loading Korean fonts" << _locale.name();
if(QFontDatabase::addApplicationFont(":/fonts/NanumGothic-Regular") < 0) { if(QFontDatabase::addApplicationFont(":/fonts/NanumGothic-Regular") < 0) {
qWarning() << "Could not load /fonts/NanumGothic-Regular font"; qWarning() << "Could not load /fonts/NanumGothic-Regular font";
} }
...@@ -426,22 +425,23 @@ void QGCApplication::setLanguage() ...@@ -426,22 +425,23 @@ void QGCApplication::setLanguage()
qWarning() << "Could not load /fonts/NanumGothic-Bold font"; qWarning() << "Could not load /fonts/NanumGothic-Bold font";
} }
} }
qDebug() << "Loading localization for" << locale.name(); qDebug() << "Loading localization for" << _locale.name();
_app->removeTranslator(&_QGCTranslator); _app->removeTranslator(&_QGCTranslator);
_app->removeTranslator(&_QGCTranslatorQt); _app->removeTranslator(&_QGCTranslatorQt);
if(_QGCTranslatorQt.load("qt_" + locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { if(_QGCTranslatorQt.load("qt_" + _locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
_app->installTranslator(&_QGCTranslatorQt); _app->installTranslator(&_QGCTranslatorQt);
} else { } else {
qDebug() << "Error loading Qt localization for" << locale.name(); qDebug() << "Error loading Qt localization for" << _locale.name();
} }
if(_QGCTranslator.load(locale, QLatin1String("qgc_"), "", ":/i18n")) { if(_QGCTranslator.load(_locale, QLatin1String("qgc_"), "", ":/i18n")) {
QLocale::setDefault(locale); QLocale::setDefault(_locale);
_app->installTranslator(&_QGCTranslator); _app->installTranslator(&_QGCTranslator);
} else { } else {
qDebug() << "Error loading application localization for" << locale.name(); qDebug() << "Error loading application localization for" << _locale.name();
} }
if(_qmlAppEngine) if(_qmlAppEngine)
_qmlAppEngine->retranslate(); _qmlAppEngine->retranslate();
emit languageChanged(_locale);
} }
void QGCApplication::_shutdown() void QGCApplication::_shutdown()
......
...@@ -118,10 +118,15 @@ public slots: ...@@ -118,10 +118,15 @@ public slots:
/// Check that the telemetry save path is set correctly /// Check that the telemetry save path is set correctly
void checkTelemetrySavePathOnMainThread(); void checkTelemetrySavePathOnMainThread();
/// Get current language
const QLocale getCurrentLanguage() { return _locale; }
signals: signals:
/// This is connected to MAVLinkProtocol::checkForLostLogFiles. We signal this to ourselves to call the slot /// This is connected to MAVLinkProtocol::checkForLostLogFiles. We signal this to ourselves to call the slot
/// on the MAVLinkProtocol thread; /// on the MAVLinkProtocol thread;
void checkForLostLogFiles(); void checkForLostLogFiles ();
void languageChanged (const QLocale locale);
public: public:
// Although public, these methods are internal and should only be called by UnitTest code // Although public, these methods are internal and should only be called by UnitTest code
...@@ -184,6 +189,7 @@ private: ...@@ -184,6 +189,7 @@ private:
bool _bluetoothAvailable = false; bool _bluetoothAvailable = false;
QTranslator _QGCTranslator; QTranslator _QGCTranslator;
QTranslator _QGCTranslatorQt; QTranslator _QGCTranslatorQt;
QLocale _locale;
static const char* _settingsVersionKey; ///< Settings key which hold settings version static const char* _settingsVersionKey; ///< Settings key which hold settings version
static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted static const char* _deleteAllSettingsKey; ///< If this settings key is set on boot, all settings will be deleted
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "ParameterManager.h" #include "ParameterManager.h"
#include "QGCApplication.h" #include "QGCApplication.h"
#include "QGCImageProvider.h" #include "QGCImageProvider.h"
#include "AudioOutput.h"
#include "FollowMe.h" #include "FollowMe.h"
#include "MissionCommandTree.h" #include "MissionCommandTree.h"
#include "QGroundControlQmlGlobal.h" #include "QGroundControlQmlGlobal.h"
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "UAS.h" #include "UAS.h"
#include "LinkInterface.h" #include "LinkInterface.h"
#include "QGC.h" #include "QGC.h"
#include "AudioOutput.h"
#include "MAVLinkProtocol.h" #include "MAVLinkProtocol.h"
#include "QGCMAVLink.h" #include "QGCMAVLink.h"
#include "LinkManager.h" #include "LinkManager.h"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment