From 500a7f07c22e6d506692d30eddcd65b34a7cb471 Mon Sep 17 00:00:00 2001 From: wwylele Date: Sat, 23 Sep 2017 16:14:20 +0300 Subject: [PATCH] cmake: generate translation file and add to resource for citra_qt --- CMakeLists.txt | 6 ++++++ dist/languages/.gitignore | 3 +++ dist/languages/.tx/config | 9 +++++++++ dist/languages/README.md | 1 + src/citra_qt/CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 dist/languages/.gitignore create mode 100644 dist/languages/.tx/config create mode 100644 dist/languages/README.md diff --git a/CMakeLists.txt b/CMakeLists.txt index b7c7c48abe..c67c129d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,10 +10,12 @@ option(ENABLE_SDL2 "Enable the SDL2 frontend" ON) option(CITRA_USE_BUNDLED_SDL2 "Download bundled SDL2 binaries" OFF) option(ENABLE_QT "Enable the Qt frontend" ON) +option(ENABLE_QT_TRANSLATION "Enable translations for the Qt frontend" OFF) option(CITRA_USE_BUNDLED_QT "Download bundled Qt binaries" OFF) option(ENABLE_WEB_SERVICE "Enable web services (telemetry, etc.)" ON) option(CITRA_USE_BUNDLED_CURL "FOR MINGW ONLY: Download curl configured against winssl instead of openssl" OFF) + if (ENABLE_WEB_SERVICE AND CITRA_USE_BUNDLED_CURL AND WINDOWS AND MSVC) message("Turning off use bundled curl as msvc can compile curl on cpr") SET(CITRA_USE_BUNDLED_CURL OFF CACHE BOOL "" FORCE) @@ -230,6 +232,10 @@ if (ENABLE_QT) endif() find_package(Qt5 REQUIRED COMPONENTS Widgets OpenGL ${QT_PREFIX_HINT}) + + if (ENABLE_QT_TRANSLATION) + find_package(Qt5 REQUIRED COMPONENTS LinguistTools ${QT_PREFIX_HINT}) + endif() endif() if (ENABLE_WEB_SERVICE) diff --git a/dist/languages/.gitignore b/dist/languages/.gitignore new file mode 100644 index 0000000000..8fc7e6a17c --- /dev/null +++ b/dist/languages/.gitignore @@ -0,0 +1,3 @@ +# Ignore the source language file +en.ts + diff --git a/dist/languages/.tx/config b/dist/languages/.tx/config new file mode 100644 index 0000000000..84d8896b40 --- /dev/null +++ b/dist/languages/.tx/config @@ -0,0 +1,9 @@ +[main] +host = https://www.transifex.com + +[citra.emulator] +file_filter = .ts +source_file = en.ts +source_lang = en +type = QT + diff --git a/dist/languages/README.md b/dist/languages/README.md new file mode 100644 index 0000000000..2156fd386b --- /dev/null +++ b/dist/languages/README.md @@ -0,0 +1 @@ +This directory stores translation patches (TS files) for citra Qt frontend. This directory is linked with [citra project on transifex](https://www.transifex.com/citra/citra), so you can update the translation by executing `tx pull -a`. If you want to contribute to the translation, please go the transifex link and submit your translation there. This directory on the main repo will be synchronized with transifex periodically. Do not directly open PRs on github to modify the translation. diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt index 9da384620d..ac472ad5ce 100644 --- a/src/citra_qt/CMakeLists.txt +++ b/src/citra_qt/CMakeLists.txt @@ -87,12 +87,46 @@ file(GLOB_RECURSE THEMES ${CMAKE_SOURCE_DIR}/dist/qt_themes/*) qt5_wrap_ui(UI_HDRS ${UIS}) +if (ENABLE_QT_TRANSLATION) + set(CITRA_QT_LANGUAGES "${CMAKE_SOURCE_DIR}/dist/languages" CACHE PATH "Path to the translation bundle for the Qt frontend") + option(GENERATE_QT_TRANSLATION "Generate en.ts as the translation source file" OFF) + + # Update source TS file if enabled + if (GENERATE_QT_TRANSLATION) + get_target_property(SRCS citra-qt SOURCES) + qt5_create_translation(QM_FILES ${SRCS} ${UIS} ${CITRA_QT_LANGUAGES}/en.ts) + add_custom_target(translation ALL DEPENDS ${CITRA_QT_LANGUAGES}/en.ts) + endif() + + # Find all TS files except en.ts + file(GLOB_RECURSE LANGUAGES_TS ${CITRA_QT_LANGUAGES}/*.ts) + list(REMOVE_ITEM LANGUAGES_TS ${CITRA_QT_LANGUAGES}/en.ts) + + # Compile TS files to QM files + qt5_add_translation(LANGUAGES_QM ${LANGUAGES_TS}) + + # Build a QRC file from the QM file list + set(LANGUAGES_QRC ${CMAKE_CURRENT_BINARY_DIR}/languages.qrc) + file(WRITE ${LANGUAGES_QRC} "\n") + foreach (QM ${LANGUAGES_QM}) + get_filename_component(QM_FILE ${QM} NAME) + file(APPEND ${LANGUAGES_QRC} "${QM_FILE}\n") + endforeach (QM) + file(APPEND ${LANGUAGES_QRC} "") + + # Add the QRC file to package in all QM files + qt5_add_resources(LANGUAGES ${LANGUAGES_QRC}) +else() + set(LANGUAGES) +endif() + target_sources(citra-qt PRIVATE ${ICONS} ${THEMES} ${UI_HDRS} ${UIS} + ${LANGUAGES} ) if (APPLE)