pax_global_header00006660000000000000000000000064145300713740014516gustar00rootroot0000000000000052 comment=164b9cf859a27277c0f15eff740f03093888d91a qtilities-qtilitools-164b9cf/000077500000000000000000000000001453007137400163465ustar00rootroot00000000000000qtilities-qtilitools-164b9cf/.editorconfig000066400000000000000000000005521453007137400210250ustar00rootroot00000000000000# EditorConfig configuration # http://editorconfig.org # Top-most EditorConfig file root = true # UTF-8 charset, set indent to spaces with width of two, # with no trailing whitespaces and a newline ending every file. [*] charset = utf-8 indent_size = 4 indent_style = space insert_final_newline = true trim_trailing_whitespace = true [*.{sh}] indent_size = 2 qtilities-qtilitools-164b9cf/.gitattributes000066400000000000000000000002321453007137400212360ustar00rootroot00000000000000# See https://help.github.com/en/articles/dealing-with-line-endings # Set the default behavior, in case people don't have core.autocrlf set. * text=auto qtilities-qtilitools-164b9cf/.gitignore000066400000000000000000000000371453007137400203360ustar00rootroot00000000000000*build*/ *.diff *.patch *.user qtilities-qtilitools-164b9cf/CMakeLists.txt000066400000000000000000000033271453007137400211130ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.15) project(Qtilitools VERSION 0.1.1 ) string(TOLOWER ${PROJECT_NAME} PROJECT_ID) set(PROJECT_FILES bin/qtls-translate cmake/QtilitoolsConfig.cmake.in cmake/modules/AppStream.cmake cmake/modules/QtAppResources.cmake cmake/modules/Translate.cmake cmake/modules/TranslateDesktop.pl README.md ) source_group("Files" FILES ${PROJECT_FILES}) add_custom_target(${PROJECT_NAME} SOURCES ${PROJECT_FILES}) if(EXISTS "/etc/os-release") file(STRINGS "/etc/os-release" distro_ REGEX "^ID=") string(REPLACE "ID=" "" distro_ "${distro_}") endif() include(CMakePackageConfigHelpers) include(GNUInstallDirs) set(QTILITOOLS_CMAKE_PATH "${CMAKE_INSTALL_DATADIR}/cmake/${PROJECT_ID}") configure_package_config_file("cmake/QtilitoolsConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/QtilitoolsConfig.cmake" PATH_VARS QTILITOOLS_CMAKE_PATH INSTALL_DESTINATION "${QTILITOOLS_CMAKE_PATH}" ) write_basic_package_version_file("QtilitoolsConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMinorVersion ARCH_INDEPENDENT ) if(distro_ STREQUAL "arch") install(FILES "COPYING" DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/${PROJECT_ID}") endif() install(PROGRAMS "bin/qtls-translate" DESTINATION "${CMAKE_INSTALL_BINDIR}") install(DIRECTORY "cmake/modules" DESTINATION "${QTILITOOLS_CMAKE_PATH}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/QtilitoolsConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/QtilitoolsConfigVersion.cmake" DESTINATION "${QTILITOOLS_CMAKE_PATH}" ) message(STATUS " Project name: ${PROJECT_NAME} Version: ${PROJECT_VERSION} System: ${CMAKE_SYSTEM} Install prefix: ${CMAKE_INSTALL_PREFIX} ") qtilities-qtilitools-164b9cf/COPYING000066400000000000000000000027351453007137400174100ustar00rootroot00000000000000BSD 3-Clause License Copyright (c) 2023, Qtilities Team Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. 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. 3. Neither the name of the copyright holder 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. qtilities-qtilitools-164b9cf/README.md000066400000000000000000000016571453007137400176360ustar00rootroot00000000000000# Qtilitools Scripts/commands used in the Qtilities organization. - **qtls-translate**: shell script based on `lxqt-transupdate` plus some additions to update and compile translations. - **AppStream.cmake**: converts a given string to a freedesktop' desktop entry specification compliant name. - **QtAppResources.cmake**: configures and installs various application' resources, including translations. - **Translate.cmake**: modified version of `LXQtTranslateTs.cmake` merged with `LXQtTranslateDesktop.cmake`, to work also with Qt6. - **TranslateDesktop.pl**: Renamed `LXQtTranslateDesktopYaml.pl` used by `Translate.cmake`. ## Build ```bash cmake -B build -D CMAKE_BUILD_TYPE=None -D CMAKE_INSTALL_PREFIX=/usr -W no-dev DESTDIR="$(pwd)/package" cmake --install build ``` ## Packages [![Packages]](https://repology.org/project/qtilitools/versions) [Packages]: https://repology.org/badge/vertical-allrepos/qtilitools.svg qtilities-qtilitools-164b9cf/bin/000077500000000000000000000000001453007137400171165ustar00rootroot00000000000000qtilities-qtilitools-164b9cf/bin/qtls-translate000077500000000000000000000063551453007137400220330ustar00rootroot00000000000000#!/bin/sh #=============================================================================== # BSD 3-Clause License # # Copyright (c) 2018, Alf Gaida (as lxqt-transupdate) # Copyright (c) 2023, Andrea Zanellato # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. 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. # # 3. Neither the name of the copyright holder 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. #=============================================================================== # qtls-translate # # Update translation files. #=============================================================================== usage() { printf "\nUse: lxqt-transupdate [source directory]\n" exit 0 } lxqt_transupdate() { if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then usage fi # Test for supported Qt version local qtVersion_=$(qmake -query QT_VERSION | cut -d'.' -f1) local qVersions_="5 6" case $qVersions_ in *"$qtVersion_"*) supported_=1 ;; esac if [ -z "$supported_" ]; then printf "\nError: Qt%s is not supported. (Supported versions are: " "$qtVersion_" printf "%s" "${qVersions_%% *}" printf ", %s" "${qVersions_#* }" printf ')\n\n' exit 1 fi local sourcedir_= local templates_=$(find . -name \*.ts | grep -v '_') if [ -d "$1" ]; then sourcedir_="$1" fi for i in $templates_; do local transdir_=$(dirname "$i") if [ "$sourcedir_" = "" ]; then sourcedir_=$(dirname "$transdir_") fi local cmdUpdateTemplate="lupdate $sourcedir_ -ts $i -locations absolute -no-obsolete" local cmdUpdateLanguage="lupdate $sourcedir_ -ts $transdir_/*_*.ts -locations absolute -no-obsolete" printf "\n== Template Update ==\n\n" printf "Running command \"%s\"...\n" "$cmdUpdateTemplate" $cmdUpdateTemplate printf "\n== Languages Update ==\n\n" printf "Running command \"%s\"...\n" "$cmdUpdateLanguage" $cmdUpdateLanguage printf "\n" done } lxqt_transupdate "${@}" qtilities-qtilitools-164b9cf/cmake/000077500000000000000000000000001453007137400174265ustar00rootroot00000000000000qtilities-qtilitools-164b9cf/cmake/QtilitoolsConfig.cmake.in000066400000000000000000000003141453007137400243240ustar00rootroot00000000000000@PACKAGE_INIT@ set_and_check(Qtilitools_CMAKE_MODULE_PATH "@PACKAGE_QTILITOOLS_CMAKE_PATH@/modules") check_required_components(Qtilitools) list(APPEND CMAKE_MODULE_PATH "${Qtilitools_CMAKE_MODULE_PATH}") qtilities-qtilitools-164b9cf/cmake/modules/000077500000000000000000000000001453007137400210765ustar00rootroot00000000000000qtilities-qtilitools-164b9cf/cmake/modules/AppStream.cmake000066400000000000000000000047571453007137400240110ustar00rootroot00000000000000#======================================================================================================= # BSD 3-Clause License # # Copyright (c) 2023, Andrea Zanellato # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. 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. # # 3. Neither the name of the copyright holder 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. #======================================================================================================= # AppStream.cmake # # Converts a domain string to a compatible AppStream ID # # E.G.: org.7-zip.7zip become org._7_zip._7zip # # See https://freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-id-generic #======================================================================================================= macro(to_appstream_id INPUT OUTPUT) set(temp_ "${INPUT}") string(REPLACE "-" "_" temp_ ${temp_}) string(REPLACE "." ";" temp_ ${temp_}) foreach(section_ ${temp_}) string(MAKE_C_IDENTIFIER "${section_}" parsed_section_) list(APPEND result_ "${parsed_section_}") endforeach() string(REPLACE ";" "." result_ "${result_}") set("${OUTPUT}" "${result_}") unset(temp_) unset(result_) endmacro() qtilities-qtilitools-164b9cf/cmake/modules/QtAppResources.cmake000066400000000000000000000135131453007137400250230ustar00rootroot00000000000000#======================================================================================================= # BSD 3-Clause License # # Copyright (c) 2023, Andrea Zanellato # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. 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. # # 3. Neither the name of the copyright holder 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. #======================================================================================================= # QtAppResources.cmake # # Configures and installs: # - About information markdown file # - Appstream metainfo # - Desktop file # - Icons # - Translations # # TODO: Windows and macOS #======================================================================================================= set(PROJECT_RESOURCES resources/about.info.md.in resources/resources.qrc ) include(GNUInstallDirs) #======================================================================================================= # Configure files #======================================================================================================= # "resources/about.md" is a gitignored file configured by cmake and then added # to the Qt resource file, so not needed in the build directory. configure_file("resources/about.info.md.in" "${CMAKE_CURRENT_SOURCE_DIR}/resources/about.md" @ONLY ) if (UNIX AND NOT APPLE) # TODO :Create a "description.html" file from PROJECT_DESCRIPTION # And insert its content into "PROJECT_APPDATA_FILE", see # (https://freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-description) # and a git tags string list from function to PROJECT_RELEASES variable # (https://freedesktop.org/software/appstream/docs/chap-Metadata.html#tag-releases) set(APPDATA_FILE_IN_ "resources/freedesktop/application.appdata.xml.in") set(DESKTOP_FILE_IN_ "resources/freedesktop/application.desktop.in") set(ICON_FILE_ "resources/icons/application.icon") set(PROJECT_APPDATA_FILE_NAME "${PROJECT_APPSTREAM_ID}.appdata.xml") set(DESKTOP_FILE_IN "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_APPSTREAM_ID}.desktop.in") list(APPEND PROJECT_RESOURCES ${APPDATA_FILE_IN_}) list(APPEND PROJECT_RESOURCES ${DESKTOP_FILE_IN_}) configure_file(${APPDATA_FILE_IN_} "${PROJECT_APPDATA_FILE_NAME}" @ONLY) configure_file(${DESKTOP_FILE_IN_} "${DESKTOP_FILE_IN}" @ONLY) unset(${APPDATA_FILE_IN_}) unset(${DESKTOP_FILE_IN_}) # Application icon might be optional if using only freedesktop theme icons if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/resources/icons/application.icon") list(APPEND PROJECT_RESOURCES ${ICON_FILE_}) set(PROJECT_ICON_FILE_PATH "${CMAKE_INSTALL_FULL_DATADIR}/icons/hicolor/scalable/apps") configure_file(${ICON_FILE_} "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_ICON_FILE_NAME}" COPYONLY ) endif() unset(ICON_FILE_) #======================================================================================================= # Translations #======================================================================================================= include(Translate) qtls_translate(PROJECT_QM_FILES SOURCES ${PROJECT_SOURCES} ${PROJECT_UI_FILES} TEMPLATE "${PROJECT_ID}" TRANSLATION_DIR "${PROJECT_TRANSLATIONS_DIR}" UPDATE_TRANSLATIONS ${PROJECT_TRANSLATIONS_UPDATE} INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_ID}/translations" ) qtls_translate_desktop(PROJECT_DESKTOP_FILES DESKTOP_FILE_STEM "${PROJECT_APPSTREAM_ID}" SOURCES "${DESKTOP_FILE_IN}" TRANSLATION_DIR "${PROJECT_TRANSLATIONS_DIR}" ) unset(DESKTOP_FILE_IN) file(GLOB PROJECT_TRANSLATION_SOURCES "${PROJECT_TRANSLATIONS_DIR}/*") source_group("Translations" FILES ${PROJECT_TRANSLATION_SOURCES}) #======================================================================================================= # Install #======================================================================================================= install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_APPDATA_FILE_NAME}" DESTINATION "${CMAKE_INSTALL_DATADIR}/metainfo" ) install(FILES "${PROJECT_DESKTOP_FILES}" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications" ) endif() if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/resources/icons/application.icon") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_ICON_FILE_NAME}" DESTINATION "${PROJECT_ICON_FILE_PATH}" ) endif() source_group("Resources" FILES ${PROJECT_RESOURCES}) qtilities-qtilitools-164b9cf/cmake/modules/Translate.cmake000066400000000000000000000162601453007137400240420ustar00rootroot00000000000000#======================================================================================================= # BSD 3-Clause License # # Copyright (c) 2014, Luís Pereira (as LXQtTranslateTs.cmake.in) # Copyright (c) 2023, Andrea Zanellato # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, this # list of conditions and the following disclaimer. # # 2. 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. # # 3. Neither the name of the copyright holder 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. # # function qtls_translate # # Output: # qmFiles Compiled ".qm" translation file names list. # # Input: # SOURCES Mandatory, the list of source files. # TEMPLATE Optional, translations base name (lower case project name). Default: "${PROJECT_ID}". # TRANSLATION_DIR Optional, ".ts" source directory path, relative to the CMakeList.txt. Default: "translations". # UPDATE_TRANSLATIONS Optional, wether if update translations or compile only. Default: OFF. # UPDATE_OPTIONS Optional, options to pass to lupdate. Requires UPDATE_TRANSLATIONS. Default: "" # INSTALL_DIR Optional, ".qm" install directory. If not present no installation is performed. #======================================================================================================= find_package(Qt${QT_VERSION_MAJOR}LinguistTools REQUIRED) # TODO: TEMPLATE as multiValueArgs? Otherwise other translations shouldn't be available as subfolder of others # because recursion. function(qtls_translate qmFiles) set(oneValueArgs UPDATE_TRANSLATIONS TEMPLATE TRANSLATION_DIR INSTALL_DIR ) set(multiValueArgs SOURCES UPDATE_OPTIONS) cmake_parse_arguments(TR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if (NOT DEFINED TR_UPDATE_TRANSLATIONS) set(TR_UPDATE_TRANSLATIONS OFF) endif() if (NOT DEFINED TR_UPDATE_OPTIONS) set(TR_UPDATE_OPTIONS "") endif() if(NOT DEFINED TR_TEMPLATE) set(TR_TEMPLATE "${PROJECT_ID}") endif() if (NOT DEFINED TR_TRANSLATION_DIR) set(TR_TRANSLATION_DIR "translations") endif() get_filename_component(TR_TRANSLATION_DIR "${TR_TRANSLATION_DIR}" ABSOLUTE) if (EXISTS "${TR_TRANSLATION_DIR}") file(GLOB tsFiles "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}_*.ts") set(templateFile "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}.ts") endif () if (TR_UPDATE_TRANSLATIONS) qt_create_translation(QMS ${TR_SOURCES} ${templateFile} OPTIONS ${TR_UPDATE_OPTIONS} ) qt_create_translation(QM ${TR_SOURCES} ${tsFiles} OPTIONS ${TR_UPDATE_OPTIONS} ) endif() qt_add_translation(QM ${tsFiles}) if(DEFINED TR_INSTALL_DIR) install(FILES ${QM} DESTINATION "${TR_INSTALL_DIR}") endif() set(${qmFiles} ${QM} PARENT_SCOPE) endfunction() #======================================================================================================= # Original Author: Alexander Sokolov # # function qtls_translate_desktop # # Output: # _RESULT The generated .desktop file(s). # # Input: # SOURCES `.desktop.in` file(s) to be merged and translated, relative to the CMakeList.txt. # DESKTOP_FILE_STEM Optional, filename, without `.desktop` extension for the output file(s). # TRANSLATION_DIR Optional, path to the directory with the .ts files, relative to the CMakeList.txt. # Default: "translations". #======================================================================================================= find_package(Perl REQUIRED) function(qtls_translate_desktop _RESULT) # Parse arguments set(oneValueArgs TRANSLATION_DIR DESKTOP_FILE_STEM) set(multiValueArgs SOURCES) cmake_parse_arguments(_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Check for unknown arguments set(_UNPARSED_ARGS ${_ARGS_UNPARSED_ARGUMENTS}) if (NOT ${_UNPARSED_ARGS} STREQUAL "") message(FATAL_ERROR "Unknown arguments '${_UNPARSED_ARGS}'.\n" "See qtls_translate_desktop() documentation for more information.\n" ) endif() if (NOT DEFINED _ARGS_SOURCES) set(${_RESULT} "" PARENT_SCOPE) return() else() set(_sources ${_ARGS_SOURCES}) endif() if (NOT DEFINED _ARGS_TRANSLATION_DIR) set(_translationDir "translations") else() set(_translationDir ${_ARGS_TRANSLATION_DIR}) endif() get_filename_component (_translationDir ${_translationDir} ABSOLUTE) foreach (_inFile ${_sources}) # File in full path string, E.g.: "/path/to/file_stem.desktop.in" get_filename_component(_inFile ${_inFile} ABSOLUTE) # File in name without extension, E.g.: "file_stem" get_filename_component(_fileName ${_inFile} NAME_WE) # File in long extension, e.g.: ".desktop.in" get_filename_component(_fileExt ${_inFile} EXT) # File output extension, e.g.: "desktop" string(REPLACE ".in" "" _fileExt ${_fileExt}) string(REGEX REPLACE "^\\.([^.].*)$" "\\1" _fileExt ${_fileExt}) if(_ARGS_DESKTOP_FILE_STEM) set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_ARGS_DESKTOP_FILE_STEM}.${_fileExt}") else() set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_fileName}.${_fileExt}") endif() get_filename_component(_outFileName ${_outFile} NAME) add_custom_command(OUTPUT ${_outFile} COMMAND ${PERL_EXECUTABLE} "${Qtilitools_CMAKE_MODULE_PATH}/TranslateDesktop.pl" "${_inFile}" "${_fileName}" "${_translationDir}/${_fileName}[_.]*${_fileExt}.yaml" >> "${_outFile}" VERBATIM COMMENT "Generating ${_outFileName}" ) set(__result ${__result} ${_outFile}) endforeach() set(${_RESULT} ${__result} PARENT_SCOPE) endfunction() qtilities-qtilitools-164b9cf/cmake/modules/TranslateDesktop.pl000066400000000000000000000030231453007137400247200ustar00rootroot00000000000000use strict; binmode(STDOUT, ":encoding(utf8)"); binmode(STDERR, ":encoding(utf8)"); my $desktop_in = $ARGV[0]; my $filename_base = $ARGV[1]; my @translation_files = glob($ARGV[2]); my $section_re = qr/^\[([^\]]+)]/o; my $lang_re = qr/^.*${filename_base}_([^.]+)\..+$/o; my $strip_re = qr/#TRANSLATIONS_DIR=/o; sub flush_translations { my ($curr_section) = @_; if (defined $curr_section) { my $transl_yaml_re = qr/^${curr_section}\/([^: ]+) ?: *([^ ].*)$/; foreach my $file (@translation_files) { my $language = ($file =~ $lang_re ? "[$1]" : ''); open(my $trans_fh, '<:encoding(UTF-8)', $file) or next; while (my $trans_l = <$trans_fh>) { if ($trans_l =~ $transl_yaml_re) { my ($key, $value) = ($1, $2); $value =~ s/^\s+|\s+$//; $value =~ s/^['"]//; $value =~ s/['"]$//; if (length($value)) { # Don't flush empty (untranslated) strings print(STDOUT "$key$language=$value\n"); } } } close($trans_fh); } } } open(my $fh, '<:encoding(UTF-8)', $desktop_in) or die "Could not open file '$desktop_in' $!"; my $curr_section = undef; while (my $line = <$fh>) { if ($line =~ $section_re) { flush_translations($curr_section); $curr_section = $1; } $line =~ $strip_re or print(STDOUT $line); } flush_translations($curr_section); close($fh);