translations.cmake 2.55 KB
Newer Older
1 2 3 4
#
# VLMC build system
# Authors: Ludovic Fauvet <etix@vlmc.org>
#          Rohit Yadav <rohityadav89@gmail.com>
5
#          Hugo Beauzée-Luyssen <hugo@beauzee.fr>
6
#
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
function(vlmc_get_ts_files VLMC_TS_FILES_OUT)
    SET(ALL_LANGUAGES
            ca
            cs
            de
            es
            eu
            fr
            gl
            el
            hu
            it
            ja
            nl
            pl
            pt
            ro
            ru
            sl
            sk
            sv
            ta
            te
            tr
            uk
            zh
       )
35

36 37 38 39 40 41 42 43 44 45 46 47 48 49
    ## Check if user has provided specific LANGS option
    if(NOT DEFINED LANGS)
        SET(VLMC_USING_LANGUAGES ${ALL_LANGUAGES} CACHE STRING "Using translations" FORCE)
    else(NOT DEFINED LANGS)
        IF(NOT LANGS)
            SET(VLMC_USING_LANGUAGES "" CACHE STRING "Using translations" FORCE)
        ELSEIF(LANGS STREQUAL *)
            SET(VLMC_USING_LANGUAGES ${ALL_LANGUAGES} CACHE STRING "Using translations" FORCE)
        ELSE(NOT LANGS)
            STRING(REGEX MATCHALL [a-zA-Z_]+
                   langs1 ${LANGS})
            SET(VLMC_USING_LANGUAGES ${langs1} CACHE STRING "Using translations" FORCE)
        ENDIF(NOT LANGS)
    endif(NOT DEFINED LANGS)
50

51 52
    ## Display what translations files will be processed
    MESSAGE(STATUS "Translations: ${VLMC_USING_LANGUAGES}")
53

54 55 56 57 58 59 60
    ## Collect all translations files that are to be processed
    FOREACH(LANGUAGE ${VLMC_USING_LANGUAGES})
        FILE(GLOB temp_TS ${CMAKE_SOURCE_DIR}/ts/vlmc*${LANGUAGE}*.ts)
        LIST(APPEND VLMC_TS_FILES ${temp_TS})
    ENDFOREACH()
    set(${VLMC_TS_FILES_OUT} ${VLMC_TS_FILES} PARENT_SCOPE)
endfunction()
61

62
function(vlmc_get_ts VLMC_QM_FILES_OUT)
63
    find_package(Qt5LinguistTools)
64 65
    if(Qt5LinguistTools_FOUND)
        vlmc_get_ts_files(vlmc_TS)
66

67 68 69 70 71 72 73 74
        ## Wraps the collected translations
        qt5_add_translation(VLMC_QM_FILES ${vlmc_TS})
        set(${VLMC_QM_FILES_OUT} ${VLMC_QM_FILES} PARENT_SCOPE)
    else()
        MESSAGE(WARNING "VLMC could not find Qt5 linguist tools. i18n support will be disabled.")
        set(${VLMC_QM_FILES_OUT} "" PARENT_SCOPE)
    endif()
endfunction()
Hugo Beauzée-Luyssen's avatar
Hugo Beauzée-Luyssen committed
75 76 77 78 79 80 81 82 83 84

function(vlmc_create_ts_resources VLMC_QMS_IN VLMC_QRC_FILE_IN)
    set(QRC_SRC "<RCC><qresource prefix=\"/ts\">")
    foreach(qm ${VLMC_QMS_IN})
        get_filename_component(QM_NAME ${qm} NAME)
        set(QRC_SRC "${QRC_SRC} <file alias=\"${QM_NAME}\">${qm}</file>")
    endforeach()
    set(QRC_SRC "${QRC_SRC}</qresource></RCC>")
    file(WRITE ${VLMC_QRC_FILE_IN} ${QRC_SRC})
endfunction()