summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2018-12-02 02:35:02 +0100
committerSlávek Banko <slavek.banko@axis.cz>2018-12-02 02:35:02 +0100
commit451ca41345a5fea5539f95829026cee9cb3ad118 (patch)
tree99b045d5d42f61236bb7e6e7de3a9199db481ba0
parent30ce93d11ae8b417599289c19aa33364c0cfa2ce (diff)
downloadtde-cmake-451ca413.tar.gz
tde-cmake-451ca413.zip
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>
-rw-r--r--modules/TDEL10n.cmake95
1 files changed, 88 insertions, 7 deletions
diff --git a/modules/TDEL10n.cmake b/modules/TDEL10n.cmake
index 166ab00..badb153 100644
--- a/modules/TDEL10n.cmake
+++ b/modules/TDEL10n.cmake
@@ -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( )