Launcher translations enabled
Translations are build into the executable at compile time, providing FGData is available during the build.
This commit is contained in:
parent
5bb3f10ba1
commit
eaa2ed5cbb
4 changed files with 67 additions and 5 deletions
|
@ -326,12 +326,15 @@ endif (USE_DBUS)
|
||||||
## Qt5 setup setup
|
## Qt5 setup setup
|
||||||
if (ENABLE_QT)
|
if (ENABLE_QT)
|
||||||
message(STATUS "Qt launcher enabled, checking for Qt >= 5.4 / qmake")
|
message(STATUS "Qt launcher enabled, checking for Qt >= 5.4 / qmake")
|
||||||
find_package(Qt5 5.4 COMPONENTS Widgets Network Qml Quick Svg)
|
find_package(Qt5 5.4 COMPONENTS Widgets Network Qml Quick Svg LinguistTools)
|
||||||
if (Qt5Widgets_FOUND)
|
if (Qt5Widgets_FOUND)
|
||||||
message(STATUS "Will enable Qt launcher GUI")
|
message(STATUS "Will enable Qt launcher GUI")
|
||||||
message(STATUS " Qt5Widgets version: ${Qt5Widgets_VERSION_STRING}")
|
message(STATUS " Qt5Widgets version: ${Qt5Widgets_VERSION_STRING}")
|
||||||
message(STATUS " Qt5Widgets include dir: ${Qt5Widgets_INCLUDE_DIRS}")
|
message(STATUS " Qt5Widgets include dir: ${Qt5Widgets_INCLUDE_DIRS}")
|
||||||
set(HAVE_QT 1)
|
set(HAVE_QT 1)
|
||||||
|
|
||||||
|
|
||||||
|
include (Translations)
|
||||||
else()
|
else()
|
||||||
# don't try to build FGQCanvas if Qt wasn't found correctly
|
# don't try to build FGQCanvas if Qt wasn't found correctly
|
||||||
set(ENABLE_FGQCANVAS OFF)
|
set(ENABLE_FGQCANVAS OFF)
|
||||||
|
|
43
CMakeModules/Translations.cmake
Normal file
43
CMakeModules/Translations.cmake
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
GET_FILENAME_COMPONENT(SRC_PARENT_DIR ${PROJECT_SOURCE_DIR} PATH)
|
||||||
|
SET(FGDATA_SRC_DIR "${SRC_PARENT_DIR}/fgdata")
|
||||||
|
|
||||||
|
if(EXISTS ${TRANSLATIONS_SRC_DIR})
|
||||||
|
message(STATUS "Using explicitly defined translations from: ${TRANSLATIONS_SRC_DIR}")
|
||||||
|
set(do_translate TRUE)
|
||||||
|
elseif(EXISTS ${FGDATA_SRC_DIR})
|
||||||
|
SET(TRANSLATIONS_SRC_DIR "${FGDATA_SRC_DIR}/Translations")
|
||||||
|
message(STATUS "Found translations dir implicitly: ${TRANSLATIONS_SRC_DIR}")
|
||||||
|
set(do_translate TRUE)
|
||||||
|
else()
|
||||||
|
message(STATUS "Couldn't find translations data, will not include translated string in the executable")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (${do_translate})
|
||||||
|
# FIXME - determine this based on subdirs of TRANSLATIONS_SRC_DIR
|
||||||
|
set(LANGUAGES en_US de es nl fr it pl pt zh_CN)
|
||||||
|
set(translation_res "${PROJECT_BINARY_DIR}/translations.qrc")
|
||||||
|
|
||||||
|
add_custom_target(fgfs_qm_files ALL)
|
||||||
|
|
||||||
|
file(WRITE ${translation_res} "<RCC>\n<qresource prefix=\"/\">")
|
||||||
|
|
||||||
|
# qm generation and installation
|
||||||
|
foreach(LANG ${LANGUAGES})
|
||||||
|
set(out_file "${PROJECT_BINARY_DIR}/FlightGear_${LANG}.qm")
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${out_file}
|
||||||
|
COMMAND Qt5::lrelease ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
|
||||||
|
-qm ${out_file}
|
||||||
|
DEPENDS ${TRANSLATIONS_SRC_DIR}/${LANG}/FlightGear-Qt.xlf
|
||||||
|
)
|
||||||
|
add_custom_target(fgfs_${LANG}_qm ALL DEPENDS ${out_file})
|
||||||
|
|
||||||
|
add_dependencies(fgfs_qm_files fgfs_${LANG}_qm)
|
||||||
|
|
||||||
|
# local path needed here, not absolute
|
||||||
|
file(APPEND ${translation_res} "<file>FlightGear_${LANG}.qm</file>\n")
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
file(APPEND ${translation_res} "</qresource>\n</RCC>")
|
||||||
|
endif() # of do translate
|
|
@ -70,7 +70,7 @@ if (HAVE_QT)
|
||||||
qt5_wrap_ui(uic_sources SetupRootDialog.ui
|
qt5_wrap_ui(uic_sources SetupRootDialog.ui
|
||||||
InstallSceneryDialog.ui
|
InstallSceneryDialog.ui
|
||||||
)
|
)
|
||||||
qt5_add_resources(qrc_sources resources.qrc)
|
qt5_add_resources(qrc_sources resources.qrc ${PROJECT_BINARY_DIR}/translations.qrc)
|
||||||
|
|
||||||
add_library(fglauncher QtLauncher.cxx
|
add_library(fglauncher QtLauncher.cxx
|
||||||
QtLauncher.hxx
|
QtLauncher.hxx
|
||||||
|
|
|
@ -42,6 +42,7 @@
|
||||||
#include <QDoubleSpinBox>
|
#include <QDoubleSpinBox>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
// Simgear
|
// Simgear
|
||||||
#include <simgear/timing/timestamp.hxx>
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
@ -206,10 +207,9 @@ private:
|
||||||
static void initQtResources()
|
static void initQtResources()
|
||||||
{
|
{
|
||||||
Q_INIT_RESOURCE(resources);
|
Q_INIT_RESOURCE(resources);
|
||||||
|
Q_INIT_RESOURCE(translations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void simgearMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
static void simgearMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
{
|
{
|
||||||
sgDebugPriority mappedPriority = SG_WARN;
|
sgDebugPriority mappedPriority = SG_WARN;
|
||||||
|
@ -240,7 +240,7 @@ namespace flightgear
|
||||||
// cleanly on quit. However, at present, the official policy is that static
|
// cleanly on quit. However, at present, the official policy is that static
|
||||||
// destruction is too late to call this, hence why we have shutdownQtApp()
|
// destruction is too late to call this, hence why we have shutdownQtApp()
|
||||||
|
|
||||||
std::unique_ptr<QApplication> static_qApp;
|
static std::unique_ptr<QApplication> static_qApp;
|
||||||
|
|
||||||
// Only requires FGGlobals to be initialized if 'doInitQSettings' is true.
|
// Only requires FGGlobals to be initialized if 'doInitQSettings' is true.
|
||||||
// Safe to call several times.
|
// Safe to call several times.
|
||||||
|
@ -285,6 +285,22 @@ void initApp(int& argc, char** argv, bool doInitQSettings)
|
||||||
static_qApp->setDesktopFileName(
|
static_qApp->setDesktopFileName(
|
||||||
QStringLiteral("org.flightgear.FlightGear.desktop"));
|
QStringLiteral("org.flightgear.FlightGear.desktop"));
|
||||||
#endif
|
#endif
|
||||||
|
QTranslator* fallbackTranslator = new QTranslator(static_qApp.get());
|
||||||
|
if (!fallbackTranslator->load(QLatin1String(":/FlightGear_en_US.qm"))) {
|
||||||
|
qWarning() << "Failed to load default (en) translations";
|
||||||
|
delete fallbackTranslator;
|
||||||
|
} else {
|
||||||
|
static_qApp->installTranslator(fallbackTranslator);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTranslator* translator = new QTranslator(static_qApp.get());
|
||||||
|
// look up e.g. :/FlightGear_de.qm
|
||||||
|
if (translator->load(QLocale(), QLatin1String("FlightGear"), QLatin1String("_"), QLatin1String(":/"))) {
|
||||||
|
qInfo() << "Loaded translations";
|
||||||
|
static_qApp->installTranslator(translator);
|
||||||
|
} else {
|
||||||
|
delete translator;
|
||||||
|
}
|
||||||
|
|
||||||
// reset numeric / collation locales as described at:
|
// reset numeric / collation locales as described at:
|
||||||
// http://doc.qt.io/qt-5/qcoreapplication.html#details
|
// http://doc.qt.io/qt-5/qcoreapplication.html#details
|
||||||
|
|
Loading…
Add table
Reference in a new issue