Unverified Commit 81c63b35 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8818 from DonLakeFlyer/JSONTranslation

Cut over to new JSON translation system
parents be44d7b2 fafd0c26
......@@ -1381,7 +1381,9 @@ AndroidBuild {
# Localization
#
TRANSLATIONS += $$files($$PWD/localization/qgc_*.ts)
TRANSLATIONS += \
$$files($$PWD/translations/qgc_source_*.ts) \
$$files($$PWD/translations/qgc_json_*.ts)
CONFIG+=lrelease embed_translations
#-------------------------------------------------------------------------------------
......
......@@ -325,7 +325,7 @@ QJsonObject JsonHelper::_translateObject(QJsonObject& jsonObject, const QString&
}
}
QString xlatString = qgcApp()->qgcTranslator().translate(translateContext.toUtf8().constData(), locString.toUtf8().constData(), disambiguation.toUtf8().constData());
QString xlatString = qgcApp()->qgcJSONTranslator().translate(translateContext.toUtf8().constData(), locString.toUtf8().constData(), disambiguation.toUtf8().constData());
if (!xlatString.isNull()) {
jsonObject[key] = xlatString;
}
......
......@@ -349,6 +349,9 @@ QGCApplication::QGCApplication(int &argc, char* argv[], bool unitTesting)
Q_UNUSED(gstDebugLevel)
#endif
// We need to set language as early as possible prior to loading on JSON files.
setLanguage();
_toolbox = new QGCToolbox(this);
_toolbox->setChildToolboxes();
......@@ -382,7 +385,7 @@ void QGCApplication::setLanguage()
_locale = QLocale::system();
qDebug() << "System reported locale:" << _locale << "; Name" << _locale.name() << "; Preffered (used in maps): " << (QLocale::system().uiLanguages().length() > 0 ? QLocale::system().uiLanguages()[0] : "None");
int langID = toolbox()->settingsManager()->appSettings()->language()->rawValue().toInt();
int langID = AppSettings::_languageID();
//-- See App.SettinsGroup.json for index
if(langID) {
switch(langID) {
......@@ -447,27 +450,35 @@ void QGCApplication::setLanguage()
}
//-- We have specific fonts for Korean
if(_locale == QLocale::Korean) {
qDebug() << "Loading Korean fonts" << _locale.name();
qCDebug(LocalizationLog) << "Loading Korean fonts" << _locale.name();
if(QFontDatabase::addApplicationFont(":/fonts/NanumGothic-Regular") < 0) {
qWarning() << "Could not load /fonts/NanumGothic-Regular font";
qCWarning(LocalizationLog) << "Could not load /fonts/NanumGothic-Regular font";
}
if(QFontDatabase::addApplicationFont(":/fonts/NanumGothic-Bold") < 0) {
qWarning() << "Could not load /fonts/NanumGothic-Bold font";
qCWarning(LocalizationLog) << "Could not load /fonts/NanumGothic-Bold font";
}
}
qDebug() << "Loading localization for" << _locale.name();
_app->removeTranslator(&_QGCTranslator);
_app->removeTranslator(&_QGCTranslatorQt);
if(_QGCTranslatorQt.load("qt_" + _locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
_app->installTranslator(&_QGCTranslatorQt);
qCDebug(LocalizationLog) << "Loading localizations for" << _locale.name();
_app->removeTranslator(&_qgcTranslatorJSON);
_app->removeTranslator(&_qgcTranslatorSourceCode);
_app->removeTranslator(&_qgcTranslatorQtLibs);
if (_locale.name() != "en_US") {
QLocale::setDefault(_locale);
if(_qgcTranslatorQtLibs.load("qt_" + _locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
_app->installTranslator(&_qgcTranslatorQtLibs);
} else {
qDebug() << "Qt localization for" << _locale.name() << "is not present";
qCWarning(LocalizationLog) << "Qt lib localization for" << _locale.name() << "is not present";
}
if(_QGCTranslator.load(_locale, QLatin1String("qgc_"), "", ":/i18n")) {
QLocale::setDefault(_locale);
_app->installTranslator(&_QGCTranslator);
if(_qgcTranslatorSourceCode.load(_locale, QLatin1String("qgc_source_"), "", ":/i18n")) {
_app->installTranslator(&_qgcTranslatorSourceCode);
} else {
qDebug() << "Error loading application localization for" << _locale.name();
qCWarning(LocalizationLog) << "Error loading source localization for" << _locale.name();
}
if(_qgcTranslatorJSON.load(_locale, QLatin1String("qgc_json_"), "", ":/i18n")) {
_app->installTranslator(&_qgcTranslatorJSON);
} else {
qCWarning(LocalizationLog) << "Error loading json localization for" << _locale.name();
}
}
if(_qmlAppEngine)
_qmlAppEngine->retranslate();
......
......@@ -98,7 +98,7 @@ public:
FactGroup* gpsRtkFactGroup(void) { return _gpsRtkFactGroup; }
QTranslator& qgcTranslator(void) { return _QGCTranslator; }
QTranslator& qgcJSONTranslator(void) { return _qgcTranslatorJSON; }
static QString cachedParameterMetaDataFile(void);
static QString cachedAirframeMetaDataFile(void);
......@@ -199,8 +199,9 @@ private:
QGCToolbox* _toolbox = nullptr;
QQuickItem* _mainRootWindow = nullptr;
bool _bluetoothAvailable = false;
QTranslator _QGCTranslator;
QTranslator _QGCTranslatorQt;
QTranslator _qgcTranslatorSourceCode; ///< translations for source code C++/Qml
QTranslator _qgcTranslatorJSON; ///< translations for json files
QTranslator _qgcTranslatorQtLibs; ///< tranlsations for Qt libraries
QLocale _locale;
bool _error = false;
QElapsedTimer _msecsElapsedTime;
......
......@@ -25,6 +25,7 @@ QGC_LOGGING_CATEGORY(GeotaggingLog, "GeotaggingLog")
QGC_LOGGING_CATEGORY(RTKGPSLog, "RTKGPSLog")
QGC_LOGGING_CATEGORY(GuidedActionsControllerLog, "GuidedActionsControllerLog")
QGC_LOGGING_CATEGORY(ADSBVehicleManagerLog, "ADSBVehicleManagerLog")
QGC_LOGGING_CATEGORY(LocalizationLog, "LocalizationLog")
QGCLoggingCategoryRegister* _instance = nullptr;
const char* QGCLoggingCategoryRegister::_filterRulesSettingsGroup = "LoggingFilters";
......
......@@ -27,6 +27,7 @@ Q_DECLARE_LOGGING_CATEGORY(GeotaggingLog)
Q_DECLARE_LOGGING_CATEGORY(RTKGPSLog)
Q_DECLARE_LOGGING_CATEGORY(GuidedActionsControllerLog)
Q_DECLARE_LOGGING_CATEGORY(ADSBVehicleManagerLog)
Q_DECLARE_LOGGING_CATEGORY(LocalizationLog)
/// @def QGC_LOGGING_CATEGORY
/// This is a QGC specific replacement for Q_LOGGING_CATEGORY. It will register the category name into a
......
......@@ -99,9 +99,6 @@ void QGCToolbox::setChildToolboxes(void)
// SettingsManager must be first so settings are available to any subsequent tools
_settingsManager->setToolbox(this);
// We now know the language setting to setup the translators. This makes the translators available to the subsequence tools.
qgcApp()->setLanguage();
_corePlugin->setToolbox(this);
_audioOutput->setToolbox(this);
_factSystem->setToolbox(this);
......
......@@ -267,3 +267,11 @@ void AppSettings::firstRunPromptIdsMarkIdAsShown(int id)
firstRunPromptIdsShown()->setRawValue(firstRunPromptsIdsListToVariant(rgIds));
}
}
int AppSettings::_languageID(void)
{
// Hack to provide language settings as early in the boot process as possible. Must be know
// prior to loading any json files.
QSettings settings;
return settings.value("language", 0).toInt();
}
/****************************************************************************
/***************_qgcTranslatorSourceCode***********************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
......@@ -118,6 +118,12 @@ public:
static const char* videoDirectory;
static const char* crashDirectory;
// Returns the current language setting bypassing the standard SettingsGroup path. This should only be used
// by QGCApplication::setLanguage to query the language setting as early in the boot process as possible.
// Specfically prior to any JSON files being loaded such that JSON file can be translated. Also since this
// is a one-off mechanism custom build overrides for language are not currently supported.
static int _languageID(void);
signals:
void savePathsChanged();
......@@ -125,8 +131,4 @@ private slots:
void _indoorPaletteChanged();
void _checkSavePathDirectories();
void _languageChanged();
private:
QTranslator _QGCTranslator;
};
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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