Qt: Properly ship Qt translations

This commit is contained in:
Vicki Pfau 2017-07-10 17:05:08 -07:00
parent 2ff1deed60
commit 253719d7a1
5 changed files with 22 additions and 5 deletions

View File

@ -188,6 +188,7 @@ Misc:
- Qt: Dismiss game crashing/failing dialogs when a new game loads - Qt: Dismiss game crashing/failing dialogs when a new game loads
- GBA Memory: Call crash callbacks regardless of if hard crash is enabled - GBA Memory: Call crash callbacks regardless of if hard crash is enabled
- SDL: Remove writing back obtained samples (fixes mgba.io/i/768) - SDL: Remove writing back obtained samples (fixes mgba.io/i/768)
- Qt: Properly ship Qt translations
0.6 beta 1: (2017-06-29) 0.6 beta 1: (2017-06-29)
- Initial beta for 0.6 - Initial beta for 0.6

View File

@ -228,8 +228,20 @@ if(Qt5LinguistTools_FOUND)
else() else()
qt5_add_translation(TRANSLATION_FILES ${TS_FILES}) qt5_add_translation(TRANSLATION_FILES ${TS_FILES})
endif() endif()
set(QT_QM_FILES)
if(QT_STATIC)
get_target_property(QT_CORE_LOCATION Qt5::Core LOCATION)
get_filename_component(QT_CORE_LOCATION ${QT_CORE_LOCATION} DIRECTORY)
get_filename_component(QT_QM_LOCATION "${QT_CORE_LOCATION}/../translations" ABSOLUTE)
foreach(TS ${TS_FILES})
get_filename_component(TS ${TS} NAME)
string(REGEX REPLACE "${BINARY_NAME}-(.*).ts$" "qtbase_\\1.qm" QT_QM "${TS}")
list(APPEND QT_QM_FILES "${QT_QM_LOCATION}/${QT_QM}")
endforeach()
list(APPEND TRANSLATION_FILES ${QT_QM_FILES})
endif()
add_custom_command(OUTPUT ${TRANSLATION_QRC} add_custom_command(OUTPUT ${TRANSLATION_QRC}
COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake" COMMAND ${CMAKE_COMMAND} -DTRANSLATION_QRC:FILEPATH="${TRANSLATION_QRC}" -DQM_BASE="${CMAKE_CURRENT_BINARY_DIR}" "-DTRANSLATION_FILES='${TRANSLATION_FILES}'" -P "${CMAKE_CURRENT_SOURCE_DIR}/ts.cmake"
DEPENDS ${TRANSLATION_FILES}) DEPENDS ${TRANSLATION_FILES})
qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC}) qt5_add_resources(TRANSLATION_RESOURCES ${TRANSLATION_QRC})
list(APPEND RESOURCES ${TRANSLATION_RESOURCES}) list(APPEND RESOURCES ${TRANSLATION_RESOURCES})
@ -263,7 +275,6 @@ if(APPLE OR WIN32)
set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) set_target_properties(${BINARY_NAME}-qt PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
endif() endif()
if(APPLE) if(APPLE)
message(STATUS ${CMAKE_SYSTEM_NAME})
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION) get_target_property(QTCOCOA Qt5::QCocoaIntegrationPlugin LOCATION)
get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION) get_target_property(COREAUDIO Qt5::CoreAudioPlugin LOCATION)

View File

@ -169,7 +169,7 @@ SettingsView::SettingsView(ConfigController* controller, InputController* inputC
m_ui.languages->setItemData(0, QLocale("en")); m_ui.languages->setItemData(0, QLocale("en"));
QDir ts(":/translations/"); QDir ts(":/translations/");
for (auto name : ts.entryList()) { for (auto name : ts.entryList()) {
if (!name.endsWith(".qm")) { if (!name.endsWith(".qm") || !name.startsWith(binaryName)) {
continue; continue;
} }
QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm")); QLocale locale(name.remove(QString("%0-").arg(binaryName)).remove(".qm"));

View File

@ -58,6 +58,12 @@ int main(int argc, char* argv[]) {
qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load(locale, "qt", "_", QLibraryInfo::location(QLibraryInfo::TranslationsPath));
application.installTranslator(&qtTranslator); application.installTranslator(&qtTranslator);
#ifdef QT_STATIC
QTranslator qtStaticTranslator;
qtStaticTranslator.load(locale, "qtbase", "_", ":/translations/");
application.installTranslator(&qtStaticTranslator);
#endif
QTranslator langTranslator; QTranslator langTranslator;
langTranslator.load(locale, binaryName, "-", ":/translations/"); langTranslator.load(locale, binaryName, "-", ":/translations/");
application.installTranslator(&langTranslator); application.installTranslator(&langTranslator);

View File

@ -1,7 +1,6 @@
file(GLOB TRANSLATION_FILES "${QM_BASE}/*.qm")
file(WRITE ${TRANSLATION_QRC} "<RCC>\n\t<qresource prefix=\"/translations/\">\n") file(WRITE ${TRANSLATION_QRC} "<RCC>\n\t<qresource prefix=\"/translations/\">\n")
foreach(TS ${TRANSLATION_FILES}) foreach(TS ${TRANSLATION_FILES})
get_filename_component(TS_BASE "${TS}" NAME) get_filename_component(TS_BASE "${TS}" NAME)
file(APPEND ${TRANSLATION_QRC} "\t\t<file>${TS_BASE}</file>\n") file(APPEND ${TRANSLATION_QRC} "\t\t<file alias=\"${TS_BASE}\">${TS}</file>\n")
endforeach() endforeach()
file(APPEND ${TRANSLATION_QRC} "\t</qresource>\n</RCC>") file(APPEND ${TRANSLATION_QRC} "\t</qresource>\n</RCC>")