From f08dc187499d2895f50f7e2e7e99bf698b0c0738 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 4 Nov 2016 18:40:24 +0100 Subject: cmake, main: add translation support --- CMakeLists.txt | 8 ++++- cmake/opentrack-boilerplate.cmake | 20 ++++++++++++ cmake/opentrack-clean-build-directory.cmake | 2 +- cmake/opentrack-hier.cmake | 3 ++ cmake/opentrack-install.cmake | 28 +++++++++++++++++ cmake/opentrack-qt.cmake | 1 + gui/main-window.ui | 4 +-- gui/main.cpp | 9 ++++++ gui/options-dialog.ui | 47 +++++++++++++++++++++++------ 9 files changed, 108 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7329c92..a953c1e7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,9 +28,13 @@ include(opentrack-build) project(opentrack) cmake_minimum_required(VERSION 2.8.11) +set_property(GLOBAL PROPERTY opentrack-all-modules "") +set_property(GLOBAL PROPERTY opentrack-all-source-dirs "") +set(opentrack-all-translations pl_PL ru_RU) + +include(opentrack-policy) include(opentrack-word-size) include(opentrack-hier) -include(opentrack-policy) include(opentrack-qt) include(opentrack-platform) include(opentrack-boilerplate) @@ -70,3 +74,5 @@ foreach(i ${opentrack-subprojects}) get_filename_component(i ${i} DIRECTORY) add_subdirectory(${i}) endforeach() + +merge_translations() diff --git a/cmake/opentrack-boilerplate.cmake b/cmake/opentrack-boilerplate.cmake index 8efc6129..fc26f685 100644 --- a/cmake/opentrack-boilerplate.cmake +++ b/cmake/opentrack-boilerplate.cmake @@ -214,4 +214,24 @@ function(opentrack_boilerplate n) opentrack_install_pdb_current_project() endif() endif() + + set(langs "") + foreach(i ${opentrack-all-translations}) + set(t "${CMAKE_CURRENT_SOURCE_DIR}/lang/${i}.ts") + list(APPEND langs "${t}") + get_property(tt GLOBAL PROPERTY opentrack-${i}-ts) + set(tt ${tt} ${t}) + set_property(GLOBAL PROPERTY opentrack-${i}-ts ${tt}) + endforeach() + + get_property(modules GLOBAL PROPERTY opentrack-all-modules) + list(APPEND modules "${n}") + set_property(GLOBAL PROPERTY opentrack-all-modules "${modules}") + + add_custom_target(${n}-i18n + COMMAND cmake -E make_directory "${CMAKE_CURRENT_SOURCE_DIR}/lang" + COMMAND "${Qt5_DIR}/../../../bin/lupdate" -silent -recursive -no-obsolete -locations relative . -ts ${langs} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + SOURCES ${langs}) endfunction() + diff --git a/cmake/opentrack-clean-build-directory.cmake b/cmake/opentrack-clean-build-directory.cmake index bf79281e..ab9fffaf 100644 --- a/cmake/opentrack-clean-build-directory.cmake +++ b/cmake/opentrack-clean-build-directory.cmake @@ -37,7 +37,7 @@ function(cleanup_build_dir) # let's hope nothing bad happens file(REMOVE_RECURSE ${files_}) - execute_process(COMMAND cmake . WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" OUTPUT_QUIET) + #execute_process(COMMAND cmake . WORKING_DIRECTORY "${CMAKE_BINARY_DIR}" OUTPUT_QUIET) endfunction() cleanup_build_dir() diff --git a/cmake/opentrack-hier.cmake b/cmake/opentrack-hier.cmake index 195b6333..8ba62830 100644 --- a/cmake/opentrack-hier.cmake +++ b/cmake/opentrack-hier.cmake @@ -17,6 +17,7 @@ if(NOT opentrack-hier-included) set(opentrack-hier-str RUNTIME DESTINATION . LIBRARY DESTINATION .) set(opentrack-doc-pfx "./doc") set(opentrack-doc-src-pfx "./source-code") + set(opentrack-i18n-pfx "${opentrack-hier-pfx}") elseif(WIN32) set(opentrack-hier-pfx "./modules") set(opentrack-hier-path "/modules/") @@ -24,6 +25,7 @@ if(NOT opentrack-hier-included) set(opentrack-doc-pfx "./doc") set(opentrack-doc-src-pfx "./source-code") set(opentrack-hier-str RUNTIME DESTINATION ./modules/ LIBRARY DESTINATION ./modules/) + set(opentrack-i18n-pfx "./i18n") else() set(opentrack-hier-pfx "libexec/opentrack") set(opentrack-hier-path "/../libexec/opentrack/") @@ -32,6 +34,7 @@ if(NOT opentrack-hier-included) set(opentrack-doc-src-pfx "./share/doc/opentrack/source-code") set(opentrack-install-rpath "${CMAKE_INSTALL_PREFIX}/${opentrack-hier-pfx}") set(opentrack-hier-str ARCHIVE DESTINATION lib/opentrack LIBRARY DESTINATION ${opentrack-hier-pfx} RUNTIME DESTINATION bin) + set(opentrack-i18n-pfx "libexec/opentrack/i18n") endif() function(opentrack_escape_string var str) diff --git a/cmake/opentrack-install.cmake b/cmake/opentrack-install.cmake index 601c89c3..3e77e396 100644 --- a/cmake/opentrack-install.cmake +++ b/cmake/opentrack-install.cmake @@ -45,3 +45,31 @@ function(opentrack_install_sources n) endforeach() opentrack_inst2("${opentrack-doc-src-pfx}/${subdir}" FILES "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt") endfunction() + +function(merge_translations) + set(all-deps "") + + install(CODE "file(REMOVE_RECURSE \"\${CMAKE_INSTALL_PREFIX}/i18n\")") + + get_property(modules GLOBAL PROPERTY opentrack-all-modules) + + foreach(i ${opentrack-all-translations}) + get_property(ts GLOBAL PROPERTY opentrack-${i}-ts) + + set(qm-output "${CMAKE_BINARY_DIR}/${i}.qm") + + set(deps "") + foreach(k ${modules}) + list(APPEND deps "${k}-i18n") + endforeach() + + add_custom_target(i18n-lang-${i} + COMMAND "${Qt5_DIR}/../../../bin/lrelease" -nounfinished -silent ${ts} -qm "${qm-output}" + DEPENDS ${deps} + ) + list(APPEND all-deps "i18n-lang-${i}") + install(FILES "${qm-output}" DESTINATION "${opentrack-i18n-pfx}" RENAME "${i}.qm" ${opentrack-perms}) + endforeach() + add_custom_target(i18n ALL DEPENDS ${all-deps}) +endfunction() + diff --git a/cmake/opentrack-qt.cmake b/cmake/opentrack-qt.cmake index ded4ec41..bb492eda 100644 --- a/cmake/opentrack-qt.cmake +++ b/cmake/opentrack-qt.cmake @@ -22,3 +22,4 @@ if(MSVC AND NOT is-msvc EQUAL 0) endforeach() ") endif() + diff --git a/gui/main-window.ui b/gui/main-window.ui index 3340aca0..e726d4d6 100644 --- a/gui/main-window.ui +++ b/gui/main-window.ui @@ -275,7 +275,7 @@ - Raw tracker data + Raw tracker data @@ -599,7 +599,7 @@ - Game data + Game data diff --git a/gui/main.cpp b/gui/main.cpp index 763f1cb5..de904f94 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -5,6 +5,8 @@ # include # include # include +# include +# include #endif #include "migration/migration.hpp" @@ -128,6 +130,8 @@ main(int argc, char** argv) QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif QApplication::setAttribute(Qt::AA_X11InitThreads, true); + + QTranslator t; QApplication app(argc, argv); set_qt_style(); @@ -137,6 +141,11 @@ main(int argc, char** argv) add_win32_path(); #endif + // QLocale::setDefault(QLocale("pl_PL")); // force i18n for testing + + (void) t.load(QLocale(), "", "", QCoreApplication::applicationDirPath() + "/i18n", ".qm"); + (void) QCoreApplication::installTranslator(&t); + do { mem w = std::make_shared(); diff --git a/gui/options-dialog.ui b/gui/options-dialog.ui index fba5e1a2..6606e28c 100644 --- a/gui/options-dialog.ui +++ b/gui/options-dialog.ui @@ -7,7 +7,7 @@ 0 0 459 - 616 + 615 @@ -40,6 +40,9 @@ Shortcuts + + 2 + @@ -68,6 +71,12 @@ QGroupBox { border: 0; } + + 4 + + + 0 + 20 @@ -201,6 +210,12 @@ + + + 3 + 0 + + @@ -218,6 +233,12 @@ + + + 7 + 0 + + Center @@ -333,7 +354,7 @@ - Enable + Enable tray @@ -538,10 +559,10 @@ - deg. + ° - 3 + 2 -180.000000000000000 @@ -607,10 +628,10 @@ - deg. + ° - 3 + 2 -180.000000000000000 @@ -660,10 +681,10 @@ - deg. + ° - 3 + 2 -180.000000000000000 @@ -1384,12 +1405,18 @@ CSV Data Logging - + - 0 + 11 + + + 0 + 1 + + Enable - You will be asked for a filename whenever tracking starts -- cgit v1.2.3