Update TDEL10n module

+ Added the ability to extract strings using extractattr.
+ Added a description of using the tde_create_l10n_template macro.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
pull/4/head
Slávek Banko 5 years ago
parent 30ce93d11a
commit 451ca41345
No known key found for this signature in database
GPG Key ID: 608F5293A04BE668

@ -46,6 +46,16 @@ if( NOT DEFINED EXTRACTRC_EXECUTABLE )
endif( )
endif( )
if( NOT DEFINED EXTRACTATTR_EXECUTABLE )
find_program( EXTRACTATTR_EXECUTABLE
NAMES extractattr
HINTS "${TDE_PREFIX}/bin"
)
if( NOT EXTRACTATTR_EXECUTABLE )
tde_message_fatal( "extractattr is required but not found" )
endif( )
endif( )
if( NOT DEFINED XGETTEXT_EXECUTABLE )
find_program( XGETTEXT_EXECUTABLE
NAMES xgettext
@ -94,6 +104,10 @@ endfunction( )
#################################################
#####
##### tde_auto_add_l10n_subdirectories
#####
##### The function is equivalent to tde_auto_add_subdirectories, but
##### the CMakeL10n.txt file is used instead of CMakeLists.txt.
#####
function( tde_auto_add_l10n_subdirectories )
file( GLOB _dirs RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${CMAKE_CURRENT_SOURCE_DIR}/*" )
@ -110,6 +124,35 @@ endfunction( )
#################################################
#####
##### tde_create_l10n_template
#####
##### Macro is used to generate a translation template - POT file.
#####
##### Syntax:
##### tde_create_l10n_template(
##### CATALOG file_name
##### [SOURCES source_spec [source_spec]]
##### [KEYWORDS keyword [keyword]]
##### [ATTRIBUTES attrib_spec [attrib_spec]]
##### [DESTINATION directory]
##### )
#####
##### Where:
##### CATALOG determines the target file name (without pot suffix).
##### SOURCES can be specified by several options:
##### a) Do not specify anything
##### - all usual source files will be automatically searched.
##### b) Enter the directory name - for example, '.' or 'src'
##### - all the usual source files in the specified directory
##### and subdirectories will be searched.
##### c) Enter the mask - for example '*.cpp'
##### - all files with the specified mask will be searched.
##### d) Specify the name of the individual file.
##### The methods from b) to d) can be combined.
##### KEYWORDS determines additional keywords for xgettext.
##### ATTRIBUTES determines files and specification for extractattr:
##### source_spec:element,attribute[,context]
##### DESTINATION determines directory to save translation template.
#####
macro( tde_create_l10n_template )
@ -120,6 +163,7 @@ macro( tde_create_l10n_template )
unset( _desktops )
unset( _dest )
unset( _keywords )
unset( _attributes )
unset( _directive )
unset( _var )
unset( _pot )
@ -154,6 +198,13 @@ macro( tde_create_l10n_template )
set( _directive 1 )
endif( )
# found directive "ATTRIBUTES"
if( "+${_arg}" STREQUAL "+ATTRIBUTES" )
unset( _attributes )
set( _var _attributes )
set( _directive 1 )
endif( )
# collect data
if( _directive )
unset( _directive )
@ -176,7 +227,7 @@ macro( tde_create_l10n_template )
message( STATUS "Create translation template ${_potFilename}" )
# verify sources
if( NOT _sources )
if( NOT _sources AND NOT _attributes )
# add current directory
list( APPEND _sources "." )
endif( )
@ -211,13 +262,13 @@ macro( tde_create_l10n_template )
list( SORT _add_files )
list( APPEND _files ${_add_files} )
# add a single file
# add a individual file
elseif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_src} )
list( APPEND _files ${_src} )
endif( )
endforeach( )
if( NOT _files )
if( NOT _files AND NOT _attributes )
tde_message_fatal( "no source files found" )
endif( )
@ -235,14 +286,44 @@ macro( tde_create_l10n_template )
endif( )
endforeach( )
# prepare extracted-rc.cpp
if( _rcs OR _attributes )
file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.cpp "" )
list( APPEND _files extracted-rc.cpp )
endif( )
# process resource files
if( _rcs )
execute_process(
COMMAND ${EXTRACTRC_EXECUTABLE} ${_rcs}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.cpp
OUTPUT_VARIABLE _sources_rc
)
list( APPEND _files extracted-rc.cpp )
file( APPEND ${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.cpp ${_sources_rc} )
endif( )
# extract attributes
if( _attributes )
foreach( _attrib ${_attributes} )
if( ${_attrib} MATCHES "^([^:]+):(.+)$" )
string( REGEX REPLACE "^([^:]+):(.+)$" "\\1" _attrib_glob ${_attrib} )
string( REGEX REPLACE "^([^:]+):(.+)$" "\\2" _attrib_spec ${_attrib} )
file( GLOB_RECURSE _attrib_files
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/${_attrib_glob}
)
if( _attrib_files )
list( SORT _attrib_files )
execute_process(
COMMAND ${EXTRACTATTR_EXECUTABLE}
--attr=${_attrib_spec} ${_attrib_files}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE _attrib_rc
)
file( APPEND ${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.cpp ${_attrib_rc} )
endif( )
endif( )
endforeach( )
endif( )
# pick desktop files *.desktop and *.protocol
@ -312,7 +393,7 @@ macro( tde_create_l10n_template )
if( _pot )
# update references for resources to original files and line numbers
if( _rcs )
if( _rcs OR _attributes )
file( STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.cpp" _extractedRC )
list( LENGTH _extractedRC _extractedRC_len )
set( _rcPos 0 )
@ -346,7 +427,7 @@ macro( tde_create_l10n_template )
endif( _pot )
# cleanup
if( _rcs )
if( _rcs OR _attributes )
file( REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/extracted-rc.cpp )
endif( )

Loading…
Cancel
Save