From 5d4f2b11c300d85ef0030575746db2f187bf21e7 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sun, 6 Jul 2008 23:47:00 +0200 Subject: [PATCH] Generate translation files rather than packaging them --- CMakeLists.txt | 8 ++- .../modules/QuasselGenerateTranslations.cmake | 66 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/QuasselGenerateTranslations.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 16dac306..884097f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,8 @@ option(DEPLOY "Mac OS X only! Adds required libs to bundle resources and option(SPUTDEV "Do not use!" OFF) set(QT "" CACHE STRING "Path to a Qt installation to use instead of the system Qt") - +set(LINGUAS "" CACHE STRING "Space-separated List of locales specifying languages that should be compiled") + if(STATIC) set(CMAKE_BUILD_TYPE Release) endif(STATIC) @@ -111,8 +112,11 @@ endif(WANT_QTCLIENT OR WANT_MONO) # Make sure version.gen exists before building mod_common add_dependencies(mod_common genversion_run) +include(QuasselGenerateTranslations) +quassel_generate_i18n_resource(RC_I18N ${LINGUAS}) + # Add resources -qt4_add_resources(RC_I18N i18n/i18n.qrc) +#qt4_add_resources(RC_I18N i18n/i18n.qrc) qt4_add_resources(RC_ICONS src/icons/icons.qrc) qt4_add_resources(RC_QUASSEL_ICONS src/icons/quassel-icons.qrc) qt4_add_resources(RC_SQL src/core/sql.qrc) diff --git a/cmake/modules/QuasselGenerateTranslations.cmake b/cmake/modules/QuasselGenerateTranslations.cmake new file mode 100644 index 00000000..6330ac58 --- /dev/null +++ b/cmake/modules/QuasselGenerateTranslations.cmake @@ -0,0 +1,66 @@ +# This file contains macros dealing with translation +# files for Quassel IRC. + +# Copyright (C) 2008 by the Quassel Project, devel@quassel-irc.org +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +macro(quassel_generate_qm outvar basename) + set(input ${CMAKE_SOURCE_DIR}/i18n/${basename}.ts) + set(output ${CMAKE_CURRENT_BINARY_DIR}/${basename}.qm) + add_custom_command(OUTPUT ${output} + COMMAND ${QT_LRELEASE_EXECUTABLE} + ARGS ${input} + -qm ${output} + -silent -compress + DEPENDS ${CMAKE_SOURCE_DIR}/i18n/${basename}.ts) + set(${outvar} ${output}) +endmacro(quassel_generate_qm outvar basename) + +macro(quassel_generate_i18n_resource outvar) + set(linguas ${ARGN}) + if(QT_LRELEASE_EXECUTABLE) + # We always include quassel.ts + quassel_generate_qm(QM quassel) + set(outfiles ${QM}) + + # Find more languages + file(GLOB avail_tsfiles ${CMAKE_SOURCE_DIR}/i18n/quassel_*.ts) + foreach(TS_FILE ${avail_tsfiles}) + get_filename_component(basename ${TS_FILE} NAME_WE) + string(REGEX REPLACE "quassel_(.+)$" "\\1" lang ${basename}) + # test if we want this + set(flg 1) + if(linguas) + string(REGEX MATCH "${lang}" flg ${linguas}) + endif(linguas) + if(flg) + quassel_generate_qm(QM ${basename}) + set(outfiles ${outfiles} ${QM}) + endif(flg) + endforeach(TS_FILE ${avail_tsfiles}) + + # Write resource file + set(resfile ${CMAKE_CURRENT_BINARY_DIR}/i18n.qrc) + file(WRITE ${resfile} "\n" + "\n") + foreach(file ${outfiles}) + get_filename_component(file ${file} NAME) + file(APPEND ${resfile} " ${file}\n") + endforeach(file ${outfiles}) + file(APPEND ${resfile} "\n\n") + add_custom_command(OUTPUT ${resfile} DEPENDS ${outfiles}) + set_directory_properties(PROPERTIES + ADDITIONAL_MAKE_CLEAN_FILES "${outfiles} i18n.qrc") + + # Generate resource + qt4_add_resources(RC_OUT ${resfile}) + set(${outvar} ${RC_OUT}) + + else(QT_LRELEASE_EXECUTABLE) + message(STATUS "WARNING: lrelease not found, you won't have translations!") + endif(QT_LRELEASE_EXECUTABLE) +endmacro(quassel_generate_i18n_resource outvar linguas) + -- 2.20.1