diff --git a/src/QGCApplication.cc b/src/QGCApplication.cc index a160e7d74720356251504cdb9f5200d28ff98bee..2958e44686e2c60df7c6f525fa09cb0acbaa0383 100644 --- a/src/QGCApplication.cc +++ b/src/QGCApplication.cc @@ -172,20 +172,6 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) { _app = this; - - QLocale locale = QLocale::system(); - //-- Some forced locales for testing - //QLocale locale = QLocale(QLocale::German); - //QLocale locale = QLocale(QLocale::French); - //QLocale locale = QLocale(QLocale::Chinese); -#if defined (__macos__) - locale = QLocale(locale.name()); -#endif - qDebug() << "System reported locale:" << locale << locale.name(); - //-- Our localization - if(_QGCTranslator.load(locale, "qgc_", "", ":/localization")) - _app->installTranslator(&_QGCTranslator); - // This prevents usage of QQuickWidget to fail since it doesn't support native widget siblings #ifndef __android__ setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); @@ -371,9 +357,49 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting) } #endif /* __mobile__ */ + setLanguage(); _checkForNewVersion(); } +void QGCApplication::setLanguage() +{ + QLocale locale = QLocale::system(); + //-- See App.SettinsGroup.json for index + int langID = toolbox()->settingsManager()->appSettings()->language()->rawValue().toInt(); + if(langID) { + switch(langID) { + case 1: + locale = QLocale(QLocale::Bulgarian); + break; + case 2: + locale = QLocale(QLocale::German); + break; + case 3: + locale = QLocale(QLocale::French); + break; + case 4: + locale = QLocale(QLocale::Italian); + break; + case 5: + locale = QLocale(QLocale::Korean); + break; + case 6: + locale = QLocale(QLocale::Russian); + break; + case 7: + locale = QLocale(QLocale::Turkish); + break; + case 8: + locale = QLocale(QLocale::Chinese); + break; + } + } + qDebug() << "System reported locale:" << locale << locale.name(); + //-- Our localization + if(_QGCTranslator.load(locale, "qgc_", "", ":/localization")) + _app->installTranslator(&_QGCTranslator); +} + void QGCApplication::_shutdown(void) { // This code is specifically not in the destructor since the application object may not be available in the destructor. diff --git a/src/QGCApplication.h b/src/QGCApplication.h index 052bf53f0318631472ad16f285f3992b815070f6..66f926b4c68554a565cb6b4d4ac4dbf1dc1388f0 100644 --- a/src/QGCApplication.h +++ b/src/QGCApplication.h @@ -101,6 +101,8 @@ public: static QString cachedParameterMetaDataFile(void); static QString cachedAirframeMetaDataFile(void); + void setLanguage(); + public slots: /// You can connect to this slot to show an information message box from a different thread. void informationMessageBoxOnMainThread(const QString& title, const QString& msg); diff --git a/src/Settings/App.SettingsGroup.json b/src/Settings/App.SettingsGroup.json index 30472a4b77bc7b85b6c72d1c4c4fd2762eaf877e..fda8fca03664d11aa90652a2db3c4e661721ea2d 100644 --- a/src/Settings/App.SettingsGroup.json +++ b/src/Settings/App.SettingsGroup.json @@ -220,12 +220,20 @@ "longDescription": "Enable Taisync Video Support", "type": "bool", "defaultValue": true -} -, +}, { "name": "enableMicrohard", "shortDescription": "Enable Microhard Module Support", "longDescription": "Enable Microhard Module Support", "type": "bool", "defaultValue": false -}] +}, +{ + "name": "language", + "shortDescription": "Language", + "type": "uint32", + "enumStrings": "System,български (Bulgarian),Deutsche (German),Français (French),Italiano (Italian),한국어 (Korean),Pусский (Russian),Türk (Turkish),中文 (Chinese)", + "enumValues": "0,1,2,3,4,5,6,7,8", + "defaultValue": 0 +} +] diff --git a/src/Settings/AppSettings.cc b/src/Settings/AppSettings.cc index ccc59052d484e967aef283937b9af85dac19d9c6..2e9962dce8529798e88e35678c938832f1a56013 100644 --- a/src/Settings/AppSettings.cc +++ b/src/Settings/AppSettings.cc @@ -59,7 +59,11 @@ DECLARE_SETTINGGROUP(App, "") connect(savePathFact, &Fact::rawValueChanged, this, &AppSettings::savePathsChanged); connect(savePathFact, &Fact::rawValueChanged, this, &AppSettings::_checkSavePathDirectories); + _checkSavePathDirectories(); + //-- Same for language + SettingsFact* languageFact = qobject_cast(language()); + connect(languageFact, &Fact::rawValueChanged, this, &AppSettings::_languageChanged); } DECLARE_SETTINGSFACT(AppSettings, offlineEditingFirmwareType) @@ -88,6 +92,7 @@ DECLARE_SETTINGSFACT(AppSettings, apmStartMavlinkStreams) DECLARE_SETTINGSFACT(AppSettings, enableTaisync) DECLARE_SETTINGSFACT(AppSettings, enableTaisyncVideo) DECLARE_SETTINGSFACT(AppSettings, enableMicrohard) +DECLARE_SETTINGSFACT(AppSettings, language) DECLARE_SETTINGSFACT_NO_FUNC(AppSettings, indoorPalette) { @@ -98,6 +103,11 @@ DECLARE_SETTINGSFACT_NO_FUNC(AppSettings, indoorPalette) return _indoorPaletteFact; } +void AppSettings::_languageChanged() +{ + qgcApp()->setLanguage(); +} + void AppSettings::_checkSavePathDirectories(void) { QDir savePathDir(savePath()->rawValue().toString()); diff --git a/src/Settings/AppSettings.h b/src/Settings/AppSettings.h index bafb8c597bcb63a6873fcc96356cc8196006d8ca..920ac30e3cfbd0190a1fdbe9ce6192d374fe6471 100644 --- a/src/Settings/AppSettings.h +++ b/src/Settings/AppSettings.h @@ -7,6 +7,7 @@ * ****************************************************************************/ #pragma once +#include #include "SettingsGroup.h" #include "QGCMAVLink.h" @@ -46,6 +47,7 @@ public: DEFINE_SETTINGFACT(enableTaisync) DEFINE_SETTINGFACT(enableTaisyncVideo) DEFINE_SETTINGFACT(enableMicrohard) + DEFINE_SETTINGFACT(language) // Although this is a global setting it only affects ArduPilot vehicle since PX4 automatically starts the stream from the vehicle side DEFINE_SETTINGFACT(apmStartMavlinkStreams) @@ -102,5 +104,9 @@ signals: private slots: void _indoorPaletteChanged(); void _checkSavePathDirectories(); + void _languageChanged(); + +private: + QTranslator _QGCTranslator; }; diff --git a/src/ui/preferences/GeneralSettings.qml b/src/ui/preferences/GeneralSettings.qml index 783ad7293b888ea1bace5489dd2333eecc9fb39d..721aabbee4533fe3ce513e8bda1c42f07720483a 100644 --- a/src/ui/preferences/GeneralSettings.qml +++ b/src/ui/preferences/GeneralSettings.qml @@ -141,6 +141,17 @@ QGCView { anchors.horizontalCenter: parent.horizontalCenter columns: 2 + QGCLabel { + text: qsTr("Language") + visible: QGroundControl.settingsManager.appSettings.language.visible + } + FactComboBox { + Layout.preferredWidth: _comboFieldWidth + fact: QGroundControl.settingsManager.appSettings.language + indexModel: false + visible: QGroundControl.settingsManager.appSettings.language.visible + } + QGCLabel { text: qsTr("Color Scheme") visible: QGroundControl.settingsManager.appSettings.indoorPalette.visible