22# Distributed under the MIT software license, see the accompanying
33# file COPYING or http://www.opensource.org/licenses/mit-license.php.
44
5+ cmake_minimum_required (VERSION 3.22)
6+
57set (input_variables
68 PROJECT_SOURCE_DIR
79 COPYRIGHT_HOLDERS
810 LCONVERT_EXECUTABLE
911 LUPDATE_EXECUTABLE
10- PYTHON_EXECUTABLE
1112 XGETTEXT_EXECUTABLE
1213)
1314
@@ -17,6 +18,60 @@ foreach(var IN LISTS input_variables)
1718 endif ()
1819endforeach ()
1920
21+ # Extract _("...") strings for translation and convert to Qt stringdefs so that
22+ # they can be picked up by Qt linguist.
23+ function (extract_strings output )
24+ execute_process (
25+ COMMAND ${XGETTEXT_EXECUTABLE}
26+ --output =bitcoinstrings.po
27+ --no -location
28+ --from-code=utf-8
29+ --keyword=_
30+ ${ARGN}
31+ COMMAND_ERROR_IS_FATAL ANY
32+ )
33+
34+ file (STRINGS "bitcoinstrings.po" text ENCODING "UTF-8" )
35+
36+ set (messages "${COPYRIGHT_HOLDERS} " )
37+ foreach (line IN LISTS text)
38+ if (line MATCHES "^msgid \" (.*)\" $" )
39+ set (msgid "${CMAKE_MATCH_1} " )
40+ elseif (line MATCHES "^\" (.*)\" $" )
41+ string (APPEND msgid "${CMAKE_MATCH_1} " )
42+ elseif (line MATCHES "^msgstr .*$" AND NOT msgid STREQUAL "" )
43+ # CMake uses ';' as a list separator.
44+ # We need to temporarily replace that in order to keep strings intact.
45+ string (REPLACE ";" "<cmake-semicolon>" msgid "${msgid} " )
46+ list (APPEND messages "${msgid} " )
47+ endif ()
48+ endforeach ()
49+
50+ set (content [[// Automatically generated by translate.cmake
51+
52+ #include <QtGlobal>
53+
54+ #ifdef __GNUC__
55+ #define UNUSED __attribute__((unused))
56+ #else
57+ #define UNUSED
58+ #endif
59+
60+ static const char UNUSED *bitcoin_strings[] = {
61+ ]])
62+
63+ set (prefix "QT_TRANSLATE_NOOP(\" bitcoin-core\" , \" " )
64+ set (suffix "\" ),\n " )
65+
66+ list (SORT messages)
67+ list (JOIN messages "${suffix}${prefix} " messages_str)
68+ string (APPEND content "${prefix}${messages_str}${suffix} " )
69+ string (APPEND content "};\n " )
70+ string (REPLACE "<cmake-semicolon>" ";" content "${content} " )
71+
72+ file (WRITE "${output} " "${content} " )
73+ endfunction ()
74+
2075file (GLOB_RECURSE translatable_sources
2176 "${PROJECT_SOURCE_DIR} /src/*.h"
2277 "${PROJECT_SOURCE_DIR} /src/*.cpp"
@@ -41,15 +96,8 @@ foreach(directory IN LISTS subtrees exclude_dirs)
4196 )
4297endforeach ()
4398
44- execute_process (
45- COMMAND ${CMAKE_COMMAND} -E env
46- XGETTEXT=${XGETTEXT_EXECUTABLE}
47- COPYRIGHT_HOLDERS=${COPYRIGHT_HOLDERS}
48- ${PYTHON_EXECUTABLE}
49- ${CMAKE_CURRENT_LIST_DIR} /extract_strings_qt.py
50- ${translatable_sources}
51- WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} /src
52- COMMAND_ERROR_IS_FATAL ANY
99+ extract_strings("${PROJECT_SOURCE_DIR} /src/qt/bitcoinstrings.cpp"
100+ ${translatable_sources}
53101)
54102
55103execute_process (
0 commit comments