From c93a739f84046c7476378a751ca3d8bbaeb384ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Sun, 9 Dec 2018 02:00:00 +0100 Subject: [PATCH] Update TDEL10n module + Added options for determining the destination directory. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Slávek Banko (cherry picked from commit 3779b941ef37adffa69274a53e321d2a78fb5f87) --- modules/TDEL10n.cmake | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/modules/TDEL10n.cmake b/modules/TDEL10n.cmake index dfafa1b..7af4a1b 100644 --- a/modules/TDEL10n.cmake +++ b/modules/TDEL10n.cmake @@ -12,10 +12,8 @@ ##### include essential TDE macros ############## -if( NOT DEFINED MASTER_SOURCE_DIR ) - set( MASTER_SOURCE_DIR "${CMAKE_SOURCE_DIR}" ) - include( TDEMacros ) -endif( ) +set( MASTER_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" ) +include( TDEMacros ) ##### verify required programs ################## @@ -154,6 +152,11 @@ endfunction( ) ##### ATTRIBUTES determines files and specification for extractattr: ##### source_spec:element,attribute[,context] ##### DESTINATION determines directory to save translation template. +##### The destination directory is determined as follows: +##### a) Directory is specified as an argument. +##### b) The variable POT_SOURCE_DIR is set. +##### c) There is a 'translations' directory. +##### d) There is a 'po' directory. ##### ##### Note: ##### Editing the _files list inside foreach( ${_files} ) below in the @@ -234,11 +237,27 @@ macro( tde_l10n_create_template ) if( NOT _catalog ) tde_message_fatal( "the name of the translation catalog is not defined" ) endif( ) + + # determine the destination directory + if( NOT _dest ) + if( POT_SOURCE_DIR ) + set( _dest ${POT_SOURCE_DIR} ) + elseif( EXISTS "${MASTER_SOURCE_DIR}/translations" ) + set( _dest "${MASTER_SOURCE_DIR}/translations/" ) + elseif( EXISTS "${MASTER_SOURCE_DIR}/po" ) + set( _dest "${MASTER_SOURCE_DIR}/po/" ) + else( ) + tde_message_fatal( "cannot determine destination directory" ) + endif( ) + endif( ) if( ${_dest} MATCHES "[^/]$" ) set( _dest "${_dest}/" ) endif( ) + if( ${_dest} MATCHES "^[^/]" ) + set( _dest "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}" ) + endif( ) - get_filename_component( _potFilename "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}${_catalog}.pot" ABSOLUTE ) + get_filename_component( _potFilename "${_dest}${_catalog}.pot" ABSOLUTE ) file( RELATIVE_PATH _potFilename ${CMAKE_SOURCE_DIR} ${_potFilename} ) message( STATUS "Create translation template ${_potFilename}" ) @@ -462,8 +481,8 @@ macro( tde_l10n_create_template ) string( REGEX REPLACE "\\.tde_l10n(:[0-9]+)" "\\1" _pot ${_pot} ) # save translation template - if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}${_catalog}.pot" ) - file( READ "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}${_catalog}.pot" _potOrig ) + if( EXISTS "${_dest}${_catalog}.pot" ) + file( READ "${_dest}${_catalog}.pot" _potOrig ) else( ) unset( _potOrig ) endif( ) @@ -472,7 +491,7 @@ macro( tde_l10n_create_template ) string( REGEX REPLACE "\n\"POT-Creation-Date: [^\"]*\"\n" "" _potNew ${_pot} ) endif( ) if( NOT _potOrig OR NOT "${_potNew}" STREQUAL "${_potOrig}" ) - file( WRITE "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}${_catalog}.pot" ${_pot} ) + file( WRITE "${_dest}${_catalog}.pot" ${_pot} ) endif( ) endif( _pot )