From 0ab89060e9d0b09316cec40f3477f7afe20c4437 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Tue, 7 Jun 2022 00:23:56 -0500 Subject: [PATCH] Updating translation, disabling locations and line numbers in .ts files --- scwx-qt/qt6-linguist.cmake | 102 --------------------------- scwx-qt/scwx-qt.cmake | 27 +++---- scwx-qt/source/scwx/qt/main/main.cpp | 11 ++- scwx-qt/ts/scwx_en_US.ts | 22 +----- 4 files changed, 21 insertions(+), 141 deletions(-) delete mode 100644 scwx-qt/qt6-linguist.cmake diff --git a/scwx-qt/qt6-linguist.cmake b/scwx-qt/qt6-linguist.cmake deleted file mode 100644 index 8c348f74..00000000 --- a/scwx-qt/qt6-linguist.cmake +++ /dev/null @@ -1,102 +0,0 @@ -#============================================================================= -# Copyright (C) 2020 The Qt Company Ltd. -# Copyright 2005-2011 Kitware, Inc. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# -# * Neither the name of Kitware, Inc. nor the names of its -# contributors may be used to endorse or promote products derived -# from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#============================================================================= - -# Modified to remove include directories from translation - -function(qt6_create_translation_scwx _qm_files) - set(options) - set(oneValueArgs) - set(multiValueArgs OPTIONS) - - cmake_parse_arguments(_LUPDATE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - set(_lupdate_files ${_LUPDATE_UNPARSED_ARGUMENTS}) - set(_lupdate_options ${_LUPDATE_OPTIONS}) - - list(FIND _lupdate_options "-extensions" _extensions_index) - if(_extensions_index GREATER -1) - math(EXPR _extensions_index "${_extensions_index} + 1") - list(GET _lupdate_options ${_extensions_index} _extensions_list) - string(REPLACE "," ";" _extensions_list "${_extensions_list}") - list(TRANSFORM _extensions_list STRIP) - list(TRANSFORM _extensions_list REPLACE "^\." "") - list(TRANSFORM _extensions_list PREPEND "*.") - else() - set(_extensions_list "*.java;*.jui;*.ui;*.c;*.c++;*.cc;*.cpp;*.cxx;*.ch;*.h;*.h++;*.hh;*.hpp;*.hxx;*.js;*.qs;*.qml;*.qrc") - endif() - set(_my_sources) - set(_my_tsfiles) - foreach(_file ${_lupdate_files}) - get_filename_component(_ext ${_file} EXT) - get_filename_component(_abs_FILE ${_file} ABSOLUTE) - if(_ext MATCHES "ts") - list(APPEND _my_tsfiles ${_abs_FILE}) - else() - list(APPEND _my_sources ${_abs_FILE}) - endif() - endforeach() - foreach(_ts_file ${_my_tsfiles}) - if(_my_sources) - # make a list file to call lupdate on, so we don't make our commands too - # long for some systems - get_filename_component(_ts_name ${_ts_file} NAME) - set(_ts_lst_file "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_ts_name}_lst_file") - set(_lst_file_srcs) - set(_dependencies) - foreach(_lst_file_src ${_my_sources}) - set(_lst_file_srcs "${_lst_file_src}\n${_lst_file_srcs}") - if(IS_DIRECTORY ${_lst_file_src}) - list(TRANSFORM _extensions_list PREPEND "${_lst_file_src}/" OUTPUT_VARIABLE _directory_glob) - file(GLOB_RECURSE _directory_contents CONFIGURE_DEPENDS ${_directory_glob}) - list(APPEND _dependencies ${_directory_contents}) - else() - list(APPEND _dependencies "${_lst_file_src}") - endif() - endforeach() - - # get_directory_property(_inc_DIRS INCLUDE_DIRECTORIES) - # foreach(_pro_include ${_inc_DIRS}) - # get_filename_component(_abs_include "${_pro_include}" ABSOLUTE) - # set(_lst_file_srcs "-I${_pro_include}\n${_lst_file_srcs}") - # endforeach() - - file(WRITE ${_ts_lst_file} "${_lst_file_srcs}") - endif() - add_custom_command(OUTPUT ${_ts_file} - COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::lupdate - ARGS ${_lupdate_options} "@${_ts_lst_file}" -ts ${_ts_file} - DEPENDS ${_dependencies} - VERBATIM) - endforeach() - qt6_add_translation(${_qm_files} ${_my_tsfiles}) - set(${_qm_files} ${${_qm_files}} PARENT_SCOPE) -endfunction() \ No newline at end of file diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 8fbf23bc..fbe9577d 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -16,19 +16,6 @@ find_package(Freetype) find_package(geographiclib) find_package(glm) -# QtCreator supports the following variables for Android, which are identical to qmake Android variables. -# Check https://doc.qt.io/qt/deployment-android.html for more information. -# They need to be set before the find_package( ...) calls below. - -#if(ANDROID) -# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") -# if (ANDROID_ABI STREQUAL "armeabi-v7a") -# set(ANDROID_EXTRA_LIBS -# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so -# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so) -# endif() -#endif() - find_package(QT NAMES Qt6 COMPONENTS Gui LinguistTools @@ -46,8 +33,6 @@ find_package(Qt${QT_VERSION_MAJOR} Widgets REQUIRED) -include(qt6-linguist.cmake) - set(SRC_EXE_MAIN source/scwx/qt/main/main.cpp) set(HDR_MAIN source/scwx/qt/main/main_window.hpp) @@ -205,9 +190,17 @@ source_group("I18N Files" FILES ${TS_FILES}) add_library(scwx-qt OBJECT ${PROJECT_SOURCES}) set_property(TARGET scwx-qt PROPERTY AUTOMOC ON) -qt_add_executable(supercell-wx ${EXECUTABLE_SOURCES}) +qt_add_translations(scwx-qt TS_FILES ${TS_FILES} + INCLUDE_DIRECTORIES true + LUPDATE_OPTIONS -locations none -no-ui-lines) -qt6_create_translation_scwx(QM_FILES ${scwx-qt_SOURCE_DIR} ${TS_FILES}) +set_target_properties(release_translations PROPERTIES FOLDER qt) +set_target_properties(scwx-qt_lrelease PROPERTIES FOLDER qt) +set_target_properties(scwx-qt_lupdate PROPERTIES FOLDER qt) +set_target_properties(scwx-qt_other_files PROPERTIES FOLDER qt) +set_target_properties(update_translations PROPERTIES FOLDER qt) + +qt_add_executable(supercell-wx ${EXECUTABLE_SOURCES}) if (WIN32) target_compile_definitions(scwx-qt PUBLIC WIN32_LEAN_AND_MEAN) diff --git a/scwx-qt/source/scwx/qt/main/main.cpp b/scwx-qt/source/scwx/qt/main/main.cpp index ee72f4ae..594d9a53 100644 --- a/scwx-qt/source/scwx/qt/main/main.cpp +++ b/scwx-qt/source/scwx/qt/main/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include static const std::string logPrefix_ = "scwx::main"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); @@ -20,8 +21,17 @@ int main(int argc, char* argv[]) scwx::util::Logger::Initialize(); spdlog::set_level(spdlog::level::debug); + QApplication a(argc, argv); + QCoreApplication::setApplicationName("Supercell Wx"); + // Enable internationalization support + QTranslator translator; + if (translator.load(QLocale(), "scwx", "_", ":/i18n")) + { + QCoreApplication::installTranslator(&translator); + } + // Start the io_context main loop boost::asio::io_context& ioContext = scwx::util::io_context(); auto work = boost::asio::make_work_guard(ioContext); @@ -56,7 +66,6 @@ int main(int argc, char* argv[]) // Run Qt main loop int result; { - QApplication a(argc, argv); scwx::qt::main::MainWindow w; w.show(); result = a.exec(); diff --git a/scwx-qt/ts/scwx_en_US.ts b/scwx-qt/ts/scwx_en_US.ts index a5ac2368..202bf24b 100644 --- a/scwx-qt/ts/scwx_en_US.ts +++ b/scwx-qt/ts/scwx_en_US.ts @@ -1,85 +1,69 @@ - + MainWindow - Toolbox - ... - Level 3 - Radar Site - Supercell Wx - &File - &Help - Volume Coverage Pattern - VCP - Clear Air Mode - Radar Products - Level 2 - E&xit - About &Supercell Wx... - &Open... - Ctrl+O @@ -87,7 +71,6 @@ scwx::qt::main::MainWindow - Unrecognized NEXRAD Product: @@ -95,17 +78,14 @@ scwx::qt::ui::Level2SettingsWidgetImpl - Elevation - Settings - Declutter