Debian Codegraph @

tests/auto/cmake/linguist/test_i18n_merge_qt_translations/CMakeLists.txt

raw
1 # Copyright (C) 2024 The Qt Company Ltd.
2 # SPDX-License-Identifier: BSD-3-Clause
3
4 # Test description:
5 # - Specify that the project intends to provide a translation for "de".
6 # - Create fake Qt translations for "de", because qttools cannot access qttranslations in the CI.
7 # - Auto-generate a myapp_de.ts file, which will have 'language="de"' set.
8 # - Specify MERGE_QT_TRANSLATIONS to merge our fake Qt translations into myapp's translations.
9 # - Run the binary 'myapp' that checks internally whether the translation is working.
10 # The actual running is done in the CMakeLists.txt one level above this one.
11
12 cmake_minimum_required(VERSION 3.16)
13 project(test_i18n_merge_qt_translations)
14
15 find_package(Qt6 REQUIRED COMPONENTS Core LinguistTools)
16 qt_standard_project_setup(I18N_TRANSLATED_LANGUAGES de)
17
18 qt_add_executable(myapp
19 main.cpp
20 )
21 target_compile_definitions(myapp PRIVATE QT_RESTRICTED_CAST_FROM_ASCII)
22
23 # Point to the directory that contains the fake translation catalogs.
24 set(fake_translations_source_dir "${CMAKE_CURRENT_SOURCE_DIR}/fake_translations")
25 set(QT_INTERNAL_ABSOLUTE_TRANSLATIONS_DIR "${CMAKE_CURRENT_BINARY_DIR}/fake_translations")
26 file(MAKE_DIRECTORY "${QT_INTERNAL_ABSOLUTE_TRANSLATIONS_DIR}")
27
28 # Create the .qm files of our fake translation catalogs.
29 _qt_internal_get_tool_wrapper_script_path(tool_wrapper)
30 file(GLOB ts_files "${fake_translations_source_dir}/*.ts")
31 get_target_property(lrelease_path Qt6::lrelease IMPORTED_LOCATION)
32 foreach(ts_file IN LISTS ts_files)
33 get_filename_component(qm_file "${ts_file}" NAME_WLE)
34 string(PREPEND qm_file "${QT_INTERNAL_ABSOLUTE_TRANSLATIONS_DIR}/")
35 string(APPEND qm_file ".qm")
36 execute_process(
37 COMMAND ${tool_wrapper} ${lrelease_path} "${ts_file}" -qm "${qm_file}"
38 COMMAND_ECHO STDOUT
39 RESULT_VARIABLE exit_code
40 )
41 if(NOT exit_code EQUAL "0")
42 message(FATAL_ERROR "lrelease exited with code ${exit_code}.")
43 endif()
44 endforeach()
45
46 qt_add_translations(myapp
47 TS_FILE_BASE myapp
48 NO_GENERATE_PLURALS_TS_FILE
49 MERGE_QT_TRANSLATIONS
50 )