summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2020-03-21 12:13:08 +0100
committerSlávek Banko <slavek.banko@axis.cz>2020-03-23 17:28:19 +0100
commite4ea4fb5f040ff9ca930bdce032c1312515334bf (patch)
tree8a16e1daacfbc91eb509042271f6f8a9965ee53b
parent152ea86f7686459b57dda4568ec080c5a90e2904 (diff)
downloadcmake-e4ea4fb5f040ff9ca930bdce032c1312515334bf.tar.gz
cmake-e4ea4fb5f040ff9ca930bdce032c1312515334bf.zip
Update TDEL10n module
+ Add a function to prepare for extracting strings from desktop files. -- xgettext creates an incorrect reference to the source file line -- xgettext does not allow the keyword to be used as a comment Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit f07fe12daf3611403ccf868069f970d6a16e4521)
-rw-r--r--modules/TDEL10n.cmake125
1 files changed, 113 insertions, 12 deletions
diff --git a/modules/TDEL10n.cmake b/modules/TDEL10n.cmake
index 7c29dd8..27cf9ae 100644
--- a/modules/TDEL10n.cmake
+++ b/modules/TDEL10n.cmake
@@ -42,15 +42,6 @@ if( NOT DEFINED XGETTEXT_EXECUTABLE )
if( "${XGETTEXT_EXECUTABLE}" STREQUAL "XGETTEXT_EXECUTABLE-NOTFOUND" )
tde_message_fatal( "xgettext is required but not found" )
endif( )
- execute_process(
- COMMAND ${XGETTEXT_EXECUTABLE} --version
- OUTPUT_VARIABLE _xgettext_version
- ERROR_VARIABLE _xgettext_version
- )
- string( REGEX REPLACE "^xgettext[^\n]* ([^ ]*)\n.*" "\\1" _xgettext_version ${_xgettext_version} )
- if( "${_xgettext_version}" VERSION_LESS "0.19" )
- tde_message_fatal( "xgettext version >= 0.19 is required but found only ${_xgettext_version}" )
- endif( )
endif( )
if( NOT DEFINED MSGUNIQ_EXECUTABLE )
@@ -414,7 +405,9 @@ macro( tde_l10n_create_template )
unset( _keywords_desktop )
unset( _keyword )
endif( )
- list( APPEND _keywords_desktop "-k${_keyword}" )
+ if( _keyword )
+ list( APPEND _keywords_desktop "${_keyword}" )
+ endif( )
endforeach( )
# prepare resource files *.kcfg, *.rc and *.ui
@@ -561,6 +554,13 @@ macro( tde_l10n_create_template )
# process desktop files
if( _desktops )
+ # prepare desktop files
+ foreach( _src ${_desktops} )
+ tde_l10n_prepare_desktop( ${_src} KEYWORDS ${_keywords_desktop} )
+ list( REMOVE_ITEM _desktops ${_src} )
+ list( APPEND _desktops "${_src}.tde_l10n" )
+ endforeach( )
+
# create translation template for desktop files
if( _pot )
set( _withPotHeader "--omit-header" )
@@ -568,8 +568,8 @@ macro( tde_l10n_create_template )
set( _withPotHeader "--foreign-user" )
endif( )
execute_process(
- COMMAND ${XGETTEXT_EXECUTABLE} ${_withPotHeader} -L Desktop
- ${_keywords_desktop} -o - ${_desktops}
+ COMMAND ${XGETTEXT_EXECUTABLE} ${_withPotHeader} -C
+ -c -ki18n -o - ${_desktops}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _potDesktop
)
@@ -1158,3 +1158,104 @@ function( tde_l10n_prepare_xmlattr )
file( WRITE ${_target} "${_xml_l10n}" )
endfunction( )
+
+
+#################################################
+#####
+##### tde_l10n_prepare_desktop
+#####
+##### The function is used to prepare desktop style file
+##### for xgettext.
+#####
+##### Note: gettext >= 0.19 includes support for extracting
+##### strings from desktop files, but there are some drawbacks.
+#####
+
+function( tde_l10n_prepare_desktop )
+
+ unset( _source )
+ unset( _target )
+ unset( _keywords )
+ unset( _directive )
+ set( _var _source )
+
+ foreach( _arg ${ARGN} )
+
+ # found directive "SOURCE"
+ if( "+${_arg}" STREQUAL "+SOURCE" )
+ unset( _source )
+ set( _var _source )
+ set( _directive 1 )
+ endif( )
+
+ # found directive "TARGET"
+ if( "+${_arg}" STREQUAL "+TARGET" )
+ unset( _target )
+ set( _var _target )
+ set( _directive 1 )
+ endif( )
+
+ # found directive "KEYWORDS"
+ if( "+${_arg}" STREQUAL "+KEYWORDS" )
+ unset( _keywords )
+ set( _var _keywords )
+ set( _directive 1 )
+ endif( )
+
+ # collect data
+ if( _directive )
+ unset( _directive )
+ elseif( _var )
+ list( APPEND ${_var} ${_arg} )
+ endif( )
+
+ endforeach( )
+
+ # verify source
+ if( NOT _source )
+ tde_message_fatal( "no source desktop file" )
+ endif( )
+ if( NOT IS_ABSOLUTE "${_source}" )
+ set( _source "${CMAKE_CURRENT_SOURCE_DIR}/${_source}" )
+ endif( )
+ if( NOT _target )
+ set( _target "${_source}.tde_l10n" )
+ endif( )
+ if( NOT IS_ABSOLUTE "${_target}" )
+ set( _target "${CMAKE_CURRENT_SOURCE_DIR}/${_target}" )
+ endif( )
+
+ # prepare keywords
+ if( NOT _keywords )
+ tde_message_fatal( "the keywords whose strings are to be extracted are not specified" )
+ endif( )
+ string( REPLACE ";" "|" _keywords_match "(${_keywords})" )
+
+ # read file
+ file( READ ${_source} _desktop_data )
+ string( REGEX REPLACE "[^\n]" "" _desktop_len ${_desktop_data} )
+ string( LENGTH "+${_desktop_len}" _desktop_len )
+
+ # process lines
+ set( _desktop_pos 0 )
+ unset( _desktop_l10n )
+ while( _desktop_pos LESS ${_desktop_len} )
+ # pick line
+ string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _desktop_line "${_desktop_data}" )
+ string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _desktop_data "${_desktop_data}" )
+ math( EXPR _desktop_pos "${_desktop_pos}+1" )
+
+ # process line
+ if( "${_desktop_line}" MATCHES "^${_keywords_match}=" )
+ string( REGEX REPLACE "\\\"" "\\\\\"" _desktop_line "${_desktop_line}" )
+ string( REGEX REPLACE "^${_keywords_match}=([^\n]*)" "/*\\1*/i18n(\"\\2\");" _desktop_line "${_desktop_line}" )
+ else( )
+ set( _desktop_line "" )
+ endif( )
+ set( _desktop_l10n "${_desktop_l10n}${_desktop_line}\n" )
+ endwhile( )
+
+ # write file
+ file( WRITE ${_target} "${_desktop_l10n}" )
+
+endfunction( )