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>
pull/76/head
Slávek Banko 3 years ago
parent 510c8ba0d9
commit 7eac0a0f68
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -54,16 +54,6 @@ if( NOT DEFINED MSGUNIQ_EXECUTABLE )
endif( ) endif( )
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 ) if( NOT DEFINED PO4A_GETTEXTIZE_EXECUTABLE )
find_program( PO4A_GETTEXTIZE_EXECUTABLE find_program( PO4A_GETTEXTIZE_EXECUTABLE
NAMES po4a-gettextize NAMES po4a-gettextize
@ -305,7 +295,7 @@ macro( tde_l10n_create_template )
if( ${_dest} MATCHES "[^/]$" ) if( ${_dest} MATCHES "[^/]$" )
set( _dest "${_dest}/" ) set( _dest "${_dest}/" )
endif( ) endif( )
if( ${_dest} MATCHES "^[^/]" ) if( NOT IS_ABSOLUTE ${_dest} )
set( _dest "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}" ) set( _dest "${CMAKE_CURRENT_SOURCE_DIR}/${_dest}" )
endif( ) endif( )
@ -555,12 +545,6 @@ macro( tde_l10n_create_template )
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _pot 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( ) endif( )
# process desktop files # process desktop files
@ -573,13 +557,8 @@ macro( tde_l10n_create_template )
endforeach( ) endforeach( )
# create translation template for desktop files # create translation template for desktop files
if( _pot )
set( _withPotHeader "--omit-header" )
else( )
set( _withPotHeader "--foreign-user" )
endif( )
execute_process( execute_process(
COMMAND ${XGETTEXT_EXECUTABLE} ${_withPotHeader} COMMAND ${XGETTEXT_EXECUTABLE} --foreign-user
--from-code=UTF-8 -C -c -ki18n -o - ${_desktops} --from-code=UTF-8 -C -c -ki18n -o - ${_desktops}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _potDesktop OUTPUT_VARIABLE _potDesktop
@ -588,43 +567,34 @@ macro( tde_l10n_create_template )
# merge translation templates # merge translation templates
if( _potDesktop ) if( _potDesktop )
if( _pot ) if( _pot )
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) set( _pot "${_pot}\n${_potDesktop}" )
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 )
else( ) else( )
set( _pot "${_potDesktop}" ) 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( ) endif( )
endif( ) endif( )
# merge additional pot files # join additional pot files
if( _pots ) if( _pots )
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp "${_pot}" ) foreach( _extra_pot IN LISTS _pots )
execute_process( file( READ ${_extra_pot} _extra_pot )
COMMAND ${MSGCAT_EXECUTABLE} --use-first extracted-pot.tmp ${_pots} if( _extra_pot )
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} if( _pot )
OUTPUT_VARIABLE _pot set( _pot "${_pot}\n${_extra_pot}" )
) else( )
file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-pot.tmp ) set( _pot "${_extra_pot}" )
endif( )
# set charset and encoding headers endif( )
string( REPLACE "Content-Type: text/plain; charset=CHARSET" "Content-Type: text/plain; charset=UTF-8" _pot "${_pot}" ) endforeach( )
string( REPLACE "Content-Transfer-Encoding: ENCODING" "Content-Transfer-Encoding: 8bit" _pot "${_pot}" )
endif( ) endif( )
# finalize translation template # finalize translation template
if( _pot ) 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 # update references for resources to original files and line numbers
list( FIND _files "extracted-rc.tde_l10n" _extractedRC_index ) list( FIND _files "extracted-rc.tde_l10n" _extractedRC_index )
if( "${_extractedRC_index}" GREATER -1 if( "${_extractedRC_index}" GREATER -1
@ -650,6 +620,18 @@ macro( tde_l10n_create_template )
# update references for modified source files (".tde_l10n" extension) # update references for modified source files (".tde_l10n" extension)
string( REGEX REPLACE "\\.tde_l10n[0-9]*(:[0-9]+)" "\\1" _pot "${_pot}" ) 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 # replace the references for _translatorinfo with instructions in the comment
string( REGEX REPLACE string( REGEX REPLACE
"(^|\n)(#:[^\n]*) _translatorinfo:1($|[^\n]*)" "(^|\n)(#:[^\n]*) _translatorinfo:1($|[^\n]*)"

Loading…
Cancel
Save