Qt: Fix loading translations
Vicki Pfau vi@endrift.com
Tue, 31 Jan 2017 11:27:18 -0800
3 files changed,
20 insertions(+),
1 deletions(-)
M
src/platform/qt/CMakeLists.txt
→
src/platform/qt/CMakeLists.txt
@@ -236,7 +236,7 @@ else()
qt5_add_translation(TRANSLATION_FILES ${TS_FILES}) endif() add_custom_command(OUTPUT ${TRANSLATION_QRC} - COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DTRANSLATION_FILES="${TRANSLATION_FILES}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake" + COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake" DEPENDS ${TRANSLATION_FILES}) qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC}) list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
M
src/platform/qt/main.cpp
→
src/platform/qt/main.cpp
@@ -6,6 +6,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GBAApp.h" #include "Window.h" +#include <QLibraryInfo> +#include <QTranslator> + +#include <mgba/core/version.h> + #ifdef QT_STATIC #include <QtPlugin> #ifdef _WIN32@@ -18,5 +23,16 @@ #endif
int main(int argc, char* argv[]) { QGBA::GBAApp application(argc, argv); + + QLocale locale = QLocale::system(); + + QTranslator qtTranslator; + qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + application.installTranslator(&qtTranslator); + + QTranslator langTranslator; + langTranslator.load(locale, binaryName, "-", ":/translations/"); + application.installTranslator(&langTranslator); + return application.exec(); }
M
src/platform/qt/ts.cmake
→
src/platform/qt/ts.cmake
@@ -1,5 +1,8 @@
+file(GLOB TRANSLATION_FILES "${QM_BASE}/*.qm") file(WRITE ${TRANSLATION_QRC} "<RCC>\n\t<qresource prefix=\"/translations/\">\n") +message(STATUS ${TRANSLATION_FILES}) foreach(TS ${TRANSLATION_FILES}) + message(STATUS ${TS}) get_filename_component(TS_BASE "${TS}" NAME) file(APPEND ${TRANSLATION_QRC} "\t\t<file>${TS_BASE}</file>\n") endforeach()