| 1 |
# Copyright (C) 2025 The Qt Company Ltd. |
| 2 |
# SPDX-License-Identifier: BSD-3-Clause |
| 3 |
|
| 4 |
message("Updating the .ts files...") |
| 5 |
execute_process( |
| 6 |
COMMAND "${CMAKE_COMMAND}" --build . --target update_translations |
| 7 |
COMMAND_ECHO STDOUT |
| 8 |
RESULT_VARIABLE process_result |
| 9 |
) |
| 10 |
if(NOT process_result EQUAL "0") |
| 11 |
message(FATAL_ERROR "Command error: ${process_result}") |
| 12 |
endif() |
| 13 |
|
| 14 |
function(check_ts_file ts_file) |
| 15 |
message("Checking the content of '${ts_file}'...") |
| 16 |
file(READ "${ts_file}" ts_file_content) |
| 17 |
|
| 18 |
set(expected_strings |
| 19 |
"<source>%n argument(s) passed</source>" |
| 20 |
) |
| 21 |
if(ts_file MATCHES "^lib2_en\\.ts$") |
| 22 |
list(APPEND expected_strings |
| 23 |
"<numerusform>one argument passed</numerusform>" |
| 24 |
) |
| 25 |
endif() |
| 26 |
foreach(needle IN LISTS expected_strings) |
| 27 |
string(FIND "${ts_file_content}" "${needle}" pos) |
| 28 |
if(pos EQUAL "-1") |
| 29 |
message(FATAL_ERROR |
| 30 |
"Expected string '${needle}' was not found in '${ts_file}'. " |
| 31 |
"The file content is:\n${ts_file_content}" |
| 32 |
) |
| 33 |
endif() |
| 34 |
endforeach() |
| 35 |
|
| 36 |
set(forbidden_strings |
| 37 |
"<source>We must not see this in the source language" |
| 38 |
) |
| 39 |
foreach(needle IN LISTS forbidden_strings) |
| 40 |
string(FIND "${ts_file_content}" "${needle}" pos) |
| 41 |
if(NOT pos EQUAL "-1") |
| 42 |
message(FATAL_ERROR |
| 43 |
"Excluded string '${needle}' was found in '${ts_file}'. " |
| 44 |
"The file content is:\n${ts_file_content}" |
| 45 |
) |
| 46 |
endif() |
| 47 |
endforeach() |
| 48 |
endfunction() |
| 49 |
|
| 50 |
file(READ ts_files.txt ts_files_to_check) |
| 51 |
if(ts_files_to_check STREQUAL "") |
| 52 |
message(FATAL_ERROR "No .ts files to check.") |
| 53 |
endif() |
| 54 |
foreach(ts_file IN LISTS ts_files_to_check) |
| 55 |
check_ts_file("${ts_file}") |
| 56 |
endforeach() |