Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Valentin Platzgummer
qgroundcontrol
Commits
81c63b35
Unverified
Commit
81c63b35
authored
Jun 10, 2020
by
Don Gagne
Committed by
GitHub
Jun 10, 2020
Browse files
Merge pull request #8818 from DonLakeFlyer/JSONTranslation
Cut over to new JSON translation system
parents
be44d7b2
fafd0c26
Changes
45
Hide whitespace changes
Inline
Side-by-side
qgroundcontrol.pro
View file @
81c63b35
...
...
@@ -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
#-------------------------------------------------------------------------------------
...
...
src/JsonHelper.cc
View file @
81c63b35
...
...
@@ -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
()
->
qgc
JSON
Translator
().
translate
(
translateContext
.
toUtf8
().
constData
(),
locString
.
toUtf8
().
constData
(),
disambiguation
.
toUtf8
().
constData
());
if
(
!
xlatString
.
isNull
())
{
jsonObject
[
key
]
=
xlatString
;
}
...
...
src/QGCApplication.cc
View file @
81c63b35
...
...
@@ -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
()
->
a
ppSettings
()
->
language
()
->
rawValue
().
toInt
();
int
langID
=
A
ppSettings
::
_
language
ID
();
//-- 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
();
q
C
Debug
(
LocalizationLog
)
<<
"Loading Korean fonts"
<<
_locale
.
name
();
if
(
QFontDatabase
::
addApplicationFont
(
":/fonts/NanumGothic-Regular"
)
<
0
)
{
qWarning
()
<<
"Could not load /fonts/NanumGothic-Regular font"
;
q
C
Warning
(
LocalizationLog
)
<<
"Could not load /fonts/NanumGothic-Regular font"
;
}
if
(
QFontDatabase
::
addApplicationFont
(
":/fonts/NanumGothic-Bold"
)
<
0
)
{
qWarning
()
<<
"Could not load /fonts/NanumGothic-Bold font"
;
q
C
Warning
(
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
);
}
else
{
qDebug
()
<<
"Qt localization for"
<<
_locale
.
name
()
<<
"is not present"
;
}
if
(
_QGCTranslator
.
load
(
_locale
,
QLatin1String
(
"qgc_"
),
""
,
":/i18n"
))
{
qCDebug
(
LocalizationLog
)
<<
"Loading localizations for"
<<
_locale
.
name
();
_app
->
removeTranslator
(
&
_qgcTranslatorJSON
);
_app
->
removeTranslator
(
&
_qgcTranslatorSourceCode
);
_app
->
removeTranslator
(
&
_qgcTranslatorQtLibs
);
if
(
_locale
.
name
()
!=
"en_US"
)
{
QLocale
::
setDefault
(
_locale
);
_app
->
installTranslator
(
&
_QGCTranslator
);
}
else
{
qDebug
()
<<
"Error loading application localization for"
<<
_locale
.
name
();
if
(
_qgcTranslatorQtLibs
.
load
(
"qt_"
+
_locale
.
name
(),
QLibraryInfo
::
location
(
QLibraryInfo
::
TranslationsPath
)))
{
_app
->
installTranslator
(
&
_qgcTranslatorQtLibs
);
}
else
{
qCWarning
(
LocalizationLog
)
<<
"Qt lib localization for"
<<
_locale
.
name
()
<<
"is not present"
;
}
if
(
_qgcTranslatorSourceCode
.
load
(
_locale
,
QLatin1String
(
"qgc_source_"
),
""
,
":/i18n"
))
{
_app
->
installTranslator
(
&
_qgcTranslatorSourceCode
);
}
else
{
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
();
...
...
src/QGCApplication.h
View file @
81c63b35
...
...
@@ -98,7 +98,7 @@ public:
FactGroup
*
gpsRtkFactGroup
(
void
)
{
return
_gpsRtkFactGroup
;
}
QTranslator
&
qgcTranslator
(
void
)
{
return
_
QGC
Translator
;
}
QTranslator
&
qgc
JSON
Translator
(
void
)
{
return
_
qgc
Translator
JSON
;
}
static
QString
cachedParameterMetaDataFile
(
void
);
static
QString
cachedAirframeMetaDataFile
(
void
);
...
...
@@ -188,9 +188,9 @@ private:
QList
<
QPair
<
int
,
QString
>>
_missingParams
;
///< List of missing parameter component id:name
QQmlApplicationEngine
*
_qmlAppEngine
=
nullptr
;
bool
_logOutput
=
false
;
///< true: Log Qt debug output to file
bool
_fakeMobile
=
false
;
///< true: Fake ui into displaying mobile interface
bool
_settingsUpgraded
=
false
;
///< true: Settings format has been upgrade to new version
bool
_logOutput
=
false
;
///< true: Log Qt debug output to file
bool
_fakeMobile
=
false
;
///< true: Fake ui into displaying mobile interface
bool
_settingsUpgraded
=
false
;
///< true: Settings format has been upgrade to new version
int
_majorVersion
=
0
;
int
_minorVersion
=
0
;
int
_buildVersion
=
0
;
...
...
@@ -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
;
...
...
src/QGCLoggingCategory.cc
View file @
81c63b35
...
...
@@ -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"
;
...
...
src/QGCLoggingCategory.h
View file @
81c63b35
...
...
@@ -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
...
...
src/QGCToolbox.cc
View file @
81c63b35
...
...
@@ -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
);
...
...
src/Settings/AppSettings.cc
View file @
81c63b35
...
...
@@ -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
();
}
src/Settings/AppSettings.h
View file @
81c63b35
/***************
**************
***********************************************
/***************
_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
;
};
translations/qgc_bg_BG.ts
→
translations/qgc_
json_
bg_BG.ts
View file @
81c63b35
File moved
translations/qgc_de_DE.ts
→
translations/qgc_
json_
de_DE.ts
View file @
81c63b35
File moved
translations/qgc_el_GR.ts
→
translations/qgc_
json_
el_GR.ts
View file @
81c63b35
File moved
translations/qgc_es_ES.ts
→
translations/qgc_
json_
es_ES.ts
View file @
81c63b35
File moved
translations/qgc_fi_FI.ts
→
translations/qgc_
json_
fi_FI.ts
View file @
81c63b35
File moved
translations/qgc_fr_FR.ts
→
translations/qgc_
json_
fr_FR.ts
View file @
81c63b35
File moved
translations/qgc_he_IL.ts
→
translations/qgc_
json_
he_IL.ts
View file @
81c63b35
File moved
translations/qgc_it_IT.ts
→
translations/qgc_
json_
it_IT.ts
View file @
81c63b35
File moved
translations/qgc_ja_JP.ts
→
translations/qgc_
json_
ja_JP.ts
View file @
81c63b35
File moved
translations/qgc_ko_KR.ts
→
translations/qgc_
json_
ko_KR.ts
View file @
81c63b35
File moved
translations/qgc_nl_NL.ts
→
translations/qgc_
json_
nl_NL.ts
View file @
81c63b35
File moved
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment