summaryrefslogtreecommitdiffstats
path: root/modules/TDEL10n.cmake
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:27:18 +0100
commitf07fe12daf3611403ccf868069f970d6a16e4521 (patch)
tree41d02c3e295bcd87772b3773190b030091a63e75 /modules/TDEL10n.cmake
parentc6b47aacd588f01576faaa7972d04b724d8ce2c0 (diff)
downloadtde-cmake-f07fe12daf3611403ccf868069f970d6a16e4521.tar.gz
tde-cmake-f07fe12daf3611403ccf868069f970d6a16e4521.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>
Diffstat (limited to 'modules/TDEL10n.cmake')
-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( )