diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2021-07-05 03:24:11 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2021-07-07 09:57:17 +0200 |
commit | 7eac0a0f6871f89baacb761fa771474f27f59022 (patch) | |
tree | f09130d4224d8ab54e998f2f013a89b11c9726bf /modules | |
parent | 510c8ba0d9ec00152d6d783eefb8965363a6c441 (diff) | |
download | tde-cmake-7eac0a0f6871f89baacb761fa771474f27f59022.tar.gz tde-cmake-7eac0a0f6871f89baacb761fa771474f27f59022.zip |
CMakeL10n: Avoid option --use-first for msguniq call
because it causes loss of comments and information about
the location of strings in source files. Instead, clean
the ugly comments from the template.
Instead of msgcat, the CMake code is now used for joining
POT files, then repeating POT file headers are removed and
msguniq is used to merge unique strings.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/TDEL10n.cmake | 78 |
1 files changed, 30 insertions, 48 deletions
diff --git a/modules/TDEL10n.cmake b/modules/TDEL10n.cmake index 5c0db26..2faa466 100644 --- a/modules/TDEL10n.cmake +++ b/modules/TDEL10n.cmake @@ -54,16 +54,6 @@ if( NOT DEFINED MSGUNIQ_EXECUTABLE ) endif( ) endif( ) -if( NOT DEFINED MSGCAT_EXECUTABLE ) - find_program( MSGCAT_EXECUTABLE - NAMES msgcat - HINTS "${TDE_PREFIX}/bin" - ) - if( "${MSGCAT_EXECUTABLE}" STREQUAL "MSGCAT_EXECUTABLE-NOTFOUND" ) - tde_message_fatal( "msgcat is required but not found" ) - endif( ) -endif( ) - if( NOT DEFINED PO4A_GETTEXTIZE_EXECUTABLE ) find_program( PO4A_GETTEXTIZE_EXECUTABLE NAMES po4a-gettextize @@ -305,7 +295,7 @@ macro( tde_l10n_create_template ) if( ${_dest} MATCHES "[^/]$" ) set( _dest "${_dest}/" ) endif( ) - if( ${_dest} MATCHES "^[^/]" ) + if( NOT IS_ABSOLUTE ${_dest} ) set( _dest "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}" ) endif( ) @@ -555,12 +545,6 @@ macro( tde_l10n_create_template ) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE _pot ) - - # set charset and encoding headers - if( _pot ) - string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) - string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) - endif( ) endif( ) # process desktop files @@ -573,13 +557,8 @@ macro( tde_l10n_create_template ) endforeach( ) # create translation template for desktop files - if( _pot ) - set( _withPotHeader "--omit-header" ) - else( ) - set( _withPotHeader "--foreign-user" ) - endif( ) execute_process( - COMMAND ${XGETTEXT_EXECUTABLE} ${_withPotHeader} + COMMAND ${XGETTEXT_EXECUTABLE} --foreign-user --from-code=UTF-8 -C -c -ki18n -o - ${_desktops} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE _potDesktop @@ -588,43 +567,34 @@ macro( tde_l10n_create_template ) # merge translation templates if( _potDesktop ) if( _pot ) - file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) - file( APPEND ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_potDesktop}" ) - execute_process( - COMMAND ${MSGUNIQ_EXECUTABLE} --use-first - INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE _pot - ) - file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp ) + set( _pot "${_pot}\n${_potDesktop}" ) else( ) set( _pot "${_potDesktop}" ) - - # set charset and encoding headers - string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) - string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) endif( ) endif( ) endif( ) - # merge additional pot files + # join additional pot files if( _pots ) - file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) - execute_process( - COMMAND ${MSGCAT_EXECUTABLE} --use-first extracted-pot.tmp ${_pots} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - OUTPUT_VARIABLE _pot - ) - file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp ) - - # set charset and encoding headers - string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) - string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) + foreach( _extra_pot IN LISTS _pots ) + file( READ ${_extra_pot} _extra_pot ) + if( _extra_pot ) + if( _pot ) + set( _pot "${_pot}\n${_extra_pot}" ) + else( ) + set( _pot "${_extra_pot}" ) + endif( ) + endif( ) + endforeach( ) endif( ) # finalize translation template if( _pot ) + # set charset and encoding headers + string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) + string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" ) + # update references for resources to original files and line numbers list( FIND _files "extracted-rc.tde_l10n" _extractedRC_index ) if( "${_extractedRC_index}" GREATER -1 @@ -650,6 +620,18 @@ macro( tde_l10n_create_template ) # update references for modified source files (".tde_l10n" extension) string( REGEX REPLACE "\\.tde_l10n[0-9]*(:[0-9]+)" "\\1" _pot "${_pot}" ) + # merge unique strings + string( REGEX REPLACE "\n\n(#[^\n]*\n)*msgid \"\"\nmsgstr \"\"\n(\"[^\n]*\n)*\n" "\n\n" _pot "${_pot}" ) + file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) + execute_process( + COMMAND ${MSGUNIQ_EXECUTABLE} + INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + OUTPUT_VARIABLE _pot + ) + file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp ) + string( REGEX REPLACE "(^|\n)#.? #-#-#-#-# [^\n]* #-#-#-#-#\n" "\\1" _pot "${_pot}" ) + # replace the references for _translatorinfo with instructions in the comment string( REGEX REPLACE "(^|\n)(#:[^\n]*) _translatorinfo:1($|[^\n]*)" |