@ -34,16 +34,6 @@ if( NOT DEFINED KDE_XGETTEXT_EXECUTABLE )
endif ( )
endif ( )
if ( NOT DEFINED EXTRACTATTR_EXECUTABLE )
find_program ( EXTRACTATTR_EXECUTABLE
N A M E S e x t r a c t a t t r
H I N T S " $ { T D E _ P R E F I X } / b i n "
)
if ( NOT EXTRACTATTR_EXECUTABLE )
tde_message_fatal ( "extractattr is required but not found" )
endif ( )
endif ( )
if ( NOT DEFINED XGETTEXT_EXECUTABLE )
find_program ( XGETTEXT_EXECUTABLE
N A M E S x g e t t e x t
@ -153,7 +143,7 @@ endfunction( )
# # # # # K E Y W O R D S d e t e r m i n e s a d d i t i o n a l k e y w o r d s f o r x g e t t e x t .
# # # # # U s e " - " i f i s n e e d e d t o d i s a b l e d e f a u l t k e y w o r d s .
# # # # # A T T R I B U T E S d e t e r m i n e s f i l e s a n d s p e c i f i c a t i o n f o r e x t r a c t a t t r :
# # # # # s o u r c e _ s p e c : e l e m e n t , a t t r i b u t e [ , c o n t e x t ]
# # # # # s o u r c e _ s p e c : e l e m e n t , a t t r i b u t e [ , c o n t e x t ] [ [ : e l e m e n t , a t t r i b u t e [ , c o n t e x t ] ] . . . ]
# # # # # D E S T I N A T I O N d e t e r m i n e s d i r e c t o r y t o s a v e t r a n s l a t i o n t e m p l a t e .
# # # # # T h e d e s t i n a t i o n d i r e c t o r y i s d e t e r m i n e d a s f o l l o w s :
# # # # # a ) D i r e c t o r y i s s p e c i f i e d a s a n a r g u m e n t .
@ -371,19 +361,21 @@ macro( tde_l10n_create_template )
# p r e p a r e r e s o u r c e f i l e s * . k c f g , * . r c a n d * . u i
foreach ( _src ${ _files } )
if ( ${ _src } MATCHES "\\.(kcfg|rc|ui)(\\.cmake)?$" )
tde_l10n_prepare_xml ( ${ _src } )
set ( _src_index 0 )
set ( _src_l10n "${_src}.tde_l10n" )
list ( FIND _files "${_src_l10n}" _src_file_index )
while ( "${_src_file_index}" GREATER -1 )
set ( _src_l10n "${_src}.tde_l10n${_src_index}" )
list ( FIND _files "${_src_l10n}" _src_file_index )
math ( EXPR _src_index "${_src_index}+1" )
endwhile ( )
tde_l10n_prepare_xml ( SOURCE ${ _src } TARGET ${ _src_l10n } )
list ( REMOVE_ITEM _files ${ _src } )
list ( APPEND _files "${_src}.tde_l10n" )
list ( APPEND _files "${_src _l10n} " )
endif ( )
endforeach ( )
# p r e p a r e e x t r a c t e d - r c . t d e _ l 1 0 n
if ( _attributes )
file ( WRITE ${ CMAKE_CURRENT_SOURCE_DIR } /extracted-rc.tde_l10n "" )
list ( APPEND _files extracted-rc.tde_l10n )
endif ( )
# e x t r a c t a t t r i b u t e s
# p r e p a r e a t t r i b u t e s
if ( _attributes )
foreach ( _attrib ${ _attributes } )
if ( ${ _attrib } MATCHES "^([^:]+):(.+)$" )
@ -393,15 +385,34 @@ macro( tde_l10n_create_template )
R E L A T I V E $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / $ { _ a t t r i b _ g l o b }
)
if ( _excludes )
foreach ( _src ${ _attrib_files } )
foreach ( _exclude ${ _excludes } )
if ( ${ _src } MATCHES ${ _exclude } )
list ( REMOVE_ITEM _attrib_files ${ _src } )
endif ( )
endforeach ( )
endforeach ( )
endif ( )
if ( _attrib_files )
list ( SORT _attrib_files )
execute_process (
C O M M A N D $ { E X T R A C T A T T R _ E X E C U T A B L E }
- - a t t r = $ { _ a t t r i b _ s p e c } $ { _ a t t r i b _ f i l e s }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
O U T P U T _ V A R I A B L E _ a t t r i b _ r c
string ( REGEX MATCHALL "[^:]+" _attrib_spec "${_attrib_spec}" )
foreach ( _src ${ _attrib_files } )
set ( _src_index 0 )
set ( _src_l10n "${_src}.tde_l10n" )
list ( FIND _files "${_src_l10n}" _src_file_index )
while ( "${_src_file_index}" GREATER -1 )
set ( _src_l10n "${_src}.tde_l10n${_src_index}" )
list ( FIND _files "${_src_l10n}" _src_file_index )
math ( EXPR _src_index "${_src_index}+1" )
endwhile ( )
tde_l10n_prepare_xmlattr (
S O U R C E $ { _ s r c }
T A R G E T $ { _ s r c _ l 1 0 n }
A T T R I B U T E S $ { _ a t t r i b _ s p e c }
)
file ( APPEND ${ CMAKE_CURRENT_SOURCE_DIR } /extracted-rc.tde_l10n "${_attrib_rc}" )
list ( APPEND _files "${_src_l10n}" )
endforeach ( )
endif ( )
endif ( )
endforeach ( )
@ -418,7 +429,7 @@ macro( tde_l10n_create_template )
# p i c k d e s k t o p f i l e s * . d e s k t o p a n d * . p r o t o c o l
foreach ( _src ${ _files } )
if ( ${ _src } MATCHES "\\.(desktop|protocol)(\\.cmake)? (\\.tde_l10n)? $" )
if ( ${ _src } MATCHES "\\.(desktop|protocol)(\\.cmake)? $" )
list ( APPEND _desktops ${ _src } )
list ( REMOVE_ITEM _files ${ _src } )
endif ( )
@ -504,7 +515,9 @@ macro( tde_l10n_create_template )
if ( _pot )
# u p d a t e r e f e r e n c e s f o r r e s o u r c e s t o o r i g i n a l f i l e s a n d l i n e n u m b e r s
if ( _attributes )
list ( FIND _files "extracted-rc.tde_l10n" _extractedRC_index )
if ( "${_extractedRC_index}" GREATER -1
A N D E X I S T S $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } / e x t r a c t e d - r c . t d e _ l 1 0 n )
file ( READ "${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.tde_l10n" _extractedRC )
string ( REGEX REPLACE "[^\n]" "" _extractedRC_len "${_extractedRC}" )
string ( LENGTH "+${_extractedRC_len}" _extractedRC_len )
@ -524,7 +537,7 @@ macro( tde_l10n_create_template )
endif ( )
# u p d a t e r e f e r e n c e s f o r m o d i f i e d s o u r c e files ( ".tde_l10n" extension )
string ( REGEX REPLACE "\\.tde_l10n (:[0-9]+)" "\\1" _pot "${_pot}" )
string ( REGEX REPLACE "\\.tde_l10n [0-9]* (:[0-9]+)" "\\1" _pot "${_pot}" )
# s a v e t r a n s l a t i o n t e m p l a t e
if ( EXISTS "${_dest}${_catalog}.pot" )
@ -544,7 +557,7 @@ macro( tde_l10n_create_template )
# c l e a n u p
foreach ( _file ${ _files } ${ _desktops } )
if ( "${_file}" MATCHES "\\.tde_l10n $" )
if ( "${_file}" MATCHES "\\.tde_l10n [0-9]* $" )
file ( REMOVE ${ CMAKE_CURRENT_SOURCE_DIR } / ${ _file } )
endif ( )
endforeach ( )
@ -775,3 +788,243 @@ function( tde_l10n_prepare_xml )
file ( WRITE ${ _target } "${_xml_l10n}" )
endfunction ( )
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # #
# # # # # t d e _ l 1 0 n _ p r e p a r e _ x m l a t t r
# # # # #
# # # # # T h e f u n c t i o n i s u s e d t o p r e p a r e a t t r i b u t e s i n X M L f i l e
# # # # # f o r x g e t t e x t , c o m p a r a b l e t o e x t r a c t a t t r .
# # # # #
function ( tde_l10n_prepare_xmlattr )
unset ( _source )
unset ( _target )
unset ( _context )
unset ( _attribs )
unset ( _directive )
set ( _preserve "line-wrap" "lines-leading" "spaces-leading" "spaces-trailing" "spaces-multi" )
set ( _var _source )
foreach ( _arg ${ ARGN } )
# f o u n d d i r e c t i v e " S O U R C E "
if ( "+${_arg}" STREQUAL "+SOURCE" )
unset ( _source )
set ( _var _source )
set ( _directive 1 )
endif ( )
# f o u n d d i r e c t i v e " T A R G E T "
if ( "+${_arg}" STREQUAL "+TARGET" )
unset ( _target )
set ( _var _target )
set ( _directive 1 )
endif ( )
# f o u n d d i r e c t i v e " C O N T E X T "
if ( "+${_arg}" STREQUAL "+CONTEXT" )
unset ( _context )
set ( _var _context )
set ( _directive 1 )
endif ( )
# f o u n d d i r e c t i v e " A T T R I B U T E S "
if ( "+${_arg}" STREQUAL "+ATTRIBUTES" )
unset ( _attribs )
set ( _var _attribs )
set ( _directive 1 )
endif ( )
# f o u n d d i r e c t i v e " P R E S E R V E "
if ( "+${_arg}" STREQUAL "+PRESERVE" )
unset ( _preserve )
set ( _var _preserve )
set ( _directive 1 )
endif ( )
# c o l l e c t d a t a
if ( _directive )
unset ( _directive )
elseif ( _var )
list ( APPEND ${ _var } ${ _arg } )
endif ( )
endforeach ( )
# v e r i f y s o u r c e
if ( NOT _source )
tde_message_fatal ( "no source XML file" )
endif ( )
if ( NOT "${_source}" MATCHES "^/" )
set ( _source "${CMAKE_CURRENT_SOURCE_DIR}/${_source}" )
endif ( )
if ( NOT _target )
set ( _target "${_source}.tde_l10n" )
endif ( )
if ( NOT "${_target}" MATCHES "^/" )
set ( _target "${CMAKE_CURRENT_SOURCE_DIR}/${_target}" )
endif ( )
# p r e p a r e t a g s t o r e g e x p
if ( NOT _attribs )
tde_message_fatal ( "no attributes specified" )
endif ( )
unset ( _tags )
foreach ( _attrib ${ _attribs } )
string ( REGEX REPLACE "^([^,]+),.*" "\\1" _tag "${_attrib}" )
list ( APPEND _tags "${_tag}" )
endforeach ( )
list ( REMOVE_DUPLICATES _tags )
string ( REPLACE ";" "|" _tags "${_tags}" )
# r e a d f i l e
file ( READ ${ _source } _xml_data )
string ( REGEX REPLACE "[^\n]" "" _xml_len ${ _xml_data } )
string ( LENGTH "+${_xml_len}" _xml_len )
# p r o c e s s l i n e s
set ( _xml_pos 0 )
unset ( _xml_l10n )
unset ( _xml_inside_tag )
unset ( _xml_inside_attrib )
unset ( _xml_attrib_empty )
while ( _xml_pos LESS ${ _xml_len } )
# p i c k l i n e
string ( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _xml_line "${_xml_data}" )
string ( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _xml_data "${_xml_data}" )
math ( EXPR _xml_pos "${_xml_pos}+1" )
set ( _xml_newline 1 )
# p r o c e s s t a g s o n l i n e
while ( _xml_newline OR NOT "${_xml_line}" STREQUAL "" )
unset ( _xml_line_rest )
if ( NOT _xml_inside_tag )
if ( "${_xml_line}" MATCHES "<(${_tags})([ \t\n][^>]*|$)" )
set ( _xml_inside_tag 1 )
string ( REGEX MATCH "<(${_tags})([ \t\n][^>]*|$)(.*)" _xml_line "${_xml_line}" )
string ( REGEX REPLACE "^<(${_tags})[ \t\n]*.*" "\\1" _xml_tag "${_xml_line}" )
string ( REGEX REPLACE "^<(${_tags})[ \t\n]*" "" _xml_line "${_xml_line}" )
unset ( _tag_attribs )
foreach ( _attrib ${ _attribs } )
if ( "${_attrib}" MATCHES "^${_xml_tag}," )
string ( REGEX REPLACE "^([^,]+),([^,]+),?(.*)" "\\2" _attrib "${_attrib}" )
list ( APPEND _tag_attribs "${_attrib}" )
endif ( )
endforeach ( )
string ( REPLACE ";" "|" _tag_attribs "${_tag_attribs}" )
unset ( _xml_inside_attrib )
else ( )
set ( _xml_line "" )
endif ( )
endif ( )
if ( _xml_inside_tag )
if ( "${_xml_line}" MATCHES "^(([ \t]*[^>=]+=\" [^\ "]*\" ) * ) [ \ t ] * / ? > " )
unset ( _xml_inside_tag )
string ( REGEX REPLACE "^(([ \t]*[^>=]+=\" [^\ "]*\" ) * ) [ \ t ] * / ? > ( . * ) " " \ \ 3 " _ x m l _ l i n e _ r e s t " $ { _ x m l _ l i n e } " )
string ( REGEX REPLACE "^(([ \t]*[^>=]+=\" [^\ "]*\" ) * ) [ \ t ] * / ? > ( . * ) " " \ \ 1 " _ x m l _ l i n e " $ { _ x m l _ l i n e } " )
endif ( )
# p r o c e s s a t t r i b s o n l i n e
set ( _xml_attrib_line "${_xml_line}" )
while ( _xml_newline OR NOT "${_xml_attrib_line}" STREQUAL "" )
unset ( _xml_newline )
unset ( _xml_line_prefix )
unset ( _xml_line_suffix )
unset ( _xml_attrib_line_rest )
if ( NOT _xml_inside_attrib )
if ( "${_xml_attrib_line}" MATCHES "(^|[ \t]+)(${_tag_attribs})=\" " )
set ( _xml_inside_attrib 1 )
string ( REGEX MATCH "(^|[ \t]+)(${_tag_attribs})=\" ( .* ) " _xml_attrib_line " ${ _xml_attrib_line } " )
string ( REGEX REPLACE "^[ \t]*(${_tag_attribs})=\" .* " " \\1" _xml_attrib "${_xml_attrib_line}" )
string ( REGEX REPLACE "^[ \t]*(${_tag_attribs})=\" " " " _xml_attrib_line " ${ _xml_attrib_line } " )
set ( _xml_context "${_context}" )
foreach ( _attrib ${ _attribs } )
if ( "${_attrib}" MATCHES "^${_xml_tag},${_xml_attrib}," )
string ( REGEX REPLACE "^([^,]+),([^,]+),?(.*)" "\\3" _xml_context "${_attrib}" )
endif ( )
endforeach ( )
set ( _xml_line_prefix "i18n(" )
if ( _xml_context )
set ( _xml_line_prefix "${_xml_line_prefix}\" ${ _xml_context } \", " )
endif ( )
set ( _xml_attrib_empty 1 )
else ( )
set ( _xml_attrib_line "" )
endif ( )
endif ( )
if ( _xml_inside_attrib )
if ( "${_xml_attrib_line}" MATCHES "\" " )
unset ( _xml_inside_attrib )
string ( REGEX REPLACE "\" ( .* ) " " \\1" _xml_attrib_line_rest "${_xml_attrib_line}" )
string ( REGEX REPLACE "\" ( .* ) " " " _xml_attrib_line " ${ _xml_attrib_line } " )
set ( _xml_line_suffix ");" )
endif ( )
string ( REGEX REPLACE "\\\\" "\\\\\\\\" _xml_attrib_line "${_xml_attrib_line}" )
string ( REGEX REPLACE "\\\" " " \\\\\"" _xml_attrib_line "${_xml_attrib_line}" )
string ( REGEX REPLACE "\t" "\\\\t" _xml_attrib_line "${_xml_attrib_line}" )
if ( NOT ";${_preserve};" MATCHES ";entities;" )
string ( REGEX REPLACE "<" "<" _xml_attrib_line "${_xml_attrib_line}" )
string ( REGEX REPLACE ">" ">" _xml_attrib_line "${_xml_attrib_line}" )
string ( REGEX REPLACE "&" "&" _xml_attrib_line "${_xml_attrib_line}" )
endif ( )
if ( NOT ";${_preserve};" MATCHES ";spaces-leading;" )
string ( REGEX REPLACE "^ +" "" _xml_attrib_line "${_xml_attrib_line}" )
endif ( )
if ( NOT ";${_preserve};" MATCHES ";spaces-trailing;" )
string ( REGEX REPLACE " +$" "" _xml_attrib_line "${_xml_attrib_line}" )
endif ( )
if ( NOT ";${_preserve};" MATCHES ";spaces-multi;" )
string ( REGEX REPLACE " +" " " _xml_attrib_line "${_xml_attrib_line}" )
endif ( )
if ( NOT "${_xml_inside_attrib}" STREQUAL "" )
if ( ";${_preserve};" MATCHES ";line-wrap;" )
if ( ";${_preserve};" MATCHES ";lines-leading;"
O R N O T " $ { _ x m l _ a t t r i b _ l i n e } " S T R E Q U A L " " O R N O T _ x m l _ a t t r i b _ e m p t y )
set ( _xml_attrib_line "${_xml_attrib_line}\\n" )
endif ( )
elseif ( NOT "${_xml_attrib_line}" STREQUAL "" AND NOT _xml_attrib_empty )
set ( _xml_attrib_line " ${_xml_attrib_line}" )
endif ( )
endif ( )
if ( NOT "${_xml_attrib_line}" STREQUAL "" )
unset ( _xml_attrib_empty )
endif ( )
endif ( )
# d r o p e m p t y a t t r i b o n s i n g l e l i n e
if ( _xml_line_prefix AND _xml_line_suffix AND _xml_attrib_empty )
# s k i p e m p t y t r a n s l a t i o n
# a d d c u r r e n t a t t r i b t o o u t p u t
else ( )
set ( _xml_l10n "${_xml_l10n}${_xml_line_prefix}" )
if ( NOT "${_xml_attrib_line}" STREQUAL "" OR ( _xml_line_suffix AND _xml_attrib_empty ) )
set ( _xml_l10n "${_xml_l10n}\" ${ _xml_attrib_line } \"" )
endif ( )
set ( _xml_l10n "${_xml_l10n}${_xml_line_suffix}" )
endif ( )
# t a k e t h e r e s t o f t h e l i n e f o r p r o c e s s i n g
set ( _xml_attrib_line "${_xml_attrib_line_rest}" )
endwhile ( )
endif ( )
# t a k e t h e r e s t o f t h e l i n e f o r p r o c e s s i n g
unset ( _xml_newline )
set ( _xml_line "${_xml_line_rest}" )
endwhile ( )
set ( _xml_l10n "${_xml_l10n}\n" )
endwhile ( )
# w r i t e f i l e
file ( WRITE ${ _target } "${_xml_l10n}" )
endfunction ( )