1 cmake_minimum_required(VERSION 3.5)
4 # Create a desktop file with the correct translations.
7 if(NOT DESKTOP_SOURCE_FILE)
8 message(FATAL_ERROR "Script needs DESKTOP_SOURCE_FILE defined")
10 if(NOT DESKTOP_BINARY_FILE)
11 message(FATAL_ERROR "Script needs DESKTOP_BINARY_FILE defined")
14 message(FATAL_ERROR "Script needs BINARY_NAME defined")
20 # Read all the arguments given to CMake; we are looking for -- and everything
21 # that follows. Those are our language files.
22 while(ARGC LESS CMAKE_ARGC)
23 set(ARG ${CMAKE_ARGV${ARGC}})
26 list(APPEND LANG_SOURCE_FILES "${ARG}")
33 math(EXPR ARGC "${ARGC} + 1")
36 # Place holder format is @<ini_key>_<str_id>@
37 file(STRINGS "${DESKTOP_SOURCE_FILE}" PLACE_HOLDER REGEX "^@")
38 string(REGEX REPLACE "@([^_]+).*@" "\\1" INI_KEY "${PLACE_HOLDER}")
39 string(REGEX REPLACE "@[^_]+_(.*)@" "\\1" STR_ID "${PLACE_HOLDER}")
40 string(REGEX REPLACE "@(.*)@" "\\1" PLACE_HOLDER "${PLACE_HOLDER}")
42 # Get the translations
43 foreach(LANGFILE IN LISTS LANG_SOURCE_FILES)
44 file(STRINGS "${LANGFILE}" LANGLINES REGEX "^(##isocode|${STR_ID})" ENCODING UTF-8)
45 string(FIND "${LANGLINES}" "${STR_ID}" HAS_STR_ID)
49 string(REGEX REPLACE "##isocode ([^;]+).*" "\\1" ISOCODE "${LANGLINES}")
50 if("${ISOCODE}" STREQUAL "en_GB")
51 string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY}=\\1" LANGLINES "${LANGLINES}")
53 string(REGEX REPLACE "[^:]*:(.*)" "${INI_KEY}[${ISOCODE}]=\\1" LANGLINES "${LANGLINES}")
55 list(APPEND ${PLACE_HOLDER} ${LANGLINES})
57 list(SORT ${PLACE_HOLDER})
58 string(REPLACE ";" "\n" ${PLACE_HOLDER} "${${PLACE_HOLDER}}")
60 configure_file(${DESKTOP_SOURCE_FILE} ${DESKTOP_BINARY_FILE})