summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2020-03-16 15:39:33 +0100
committerSlávek Banko <slavek.banko@axis.cz>2020-03-23 17:28:19 +0100
commit152ea86f7686459b57dda4568ec080c5a90e2904 (patch)
treed64c39658015fd1e3ed2b49216c7c41f326abee1
parente0f71ec8c70cea3e44452707215af2feb8a173d1 (diff)
downloadtde-cmake-152ea86f7686459b57dda4568ec080c5a90e2904.tar.gz
tde-cmake-152ea86f7686459b57dda4568ec080c5a90e2904.zip
Add support for creation of translated desktop files during build.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz> (cherry picked from commit c6b47aacd588f01576faaa7972d04b724d8ce2c0)
-rw-r--r--modules/TDEMacros.cmake216
1 files changed, 216 insertions, 0 deletions
diff --git a/modules/TDEMacros.cmake b/modules/TDEMacros.cmake
index fbc0567..66aedf3 100644
--- a/modules/TDEMacros.cmake
+++ b/modules/TDEMacros.cmake
@@ -6,6 +6,9 @@
# (C) 2011-2012 Timothy Pearson
# kb9vqf (AT) pearsoncomputing.net
#
+# (C) 2012-2020 Slávek Banko
+# slavek (DOT) banko (AT) axis.cz
+#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 2
@@ -1523,6 +1526,204 @@ endmacro( )
#################################################
#####
+##### tde_create_translated_desktop
+#####
+##### Macro is used to merge translations into desktop file
+#####
+##### Syntax:
+##### tde_create_translated_desktop(
+##### [SOURCE] file_name
+##### [KEYWORDS keyword [keyword]]
+##### [PO_DIR po_directory]
+##### [DESTINATION directory]
+##### [OUTPUT_NAME file_name]
+##### )
+
+macro( tde_create_translated_desktop )
+
+ unset( _src )
+ unset( _keywords_add )
+ unset( _po_dir )
+ unset( _dest )
+ unset( _out_name )
+ unset( _directive )
+ set( _var _src )
+ set( _keywords_desktop_default
+ "Name" "GenericName" "Comment" "Keywords"
+ "Description" "ExtraNames" "X-TDE-Submenu" )
+
+ foreach( _arg ${ARGN} )
+
+ # found directive "SOURCE"
+ if( "+${_arg}" STREQUAL "+SOURCE" )
+ unset( _src )
+ set( _var _src )
+ set( _directive 1 )
+ endif( )
+
+ # found directive "KEYWORDS"
+ if( "+${_arg}" STREQUAL "+KEYWORDS" )
+ unset( _keywords_add )
+ set( _var _keywords_add )
+ set( _directive 1 )
+ endif( )
+
+ # found directive "PO_DIR"
+ if( "+${_arg}" STREQUAL "+PO_DIR" )
+ unset( _po_dir )
+ set( _var _po_dir )
+ set( _directive 1 )
+ endif( )
+
+ # found directive "DESTINATION"
+ if( "+${_arg}" STREQUAL "+DESTINATION" )
+ unset( _dest )
+ set( _var _dest )
+ set( _directive 1 )
+ endif( )
+
+ # found directive "OUTPUT_NAME"
+ if( "+${_arg}" STREQUAL "+OUTPUT_NAME" )
+ unset( _out_name )
+ set( _var _out_name )
+ set( _directive 1 )
+ endif( )
+
+ # collect data
+ if( _directive )
+ unset( _directive )
+ elseif( _var )
+ list( APPEND ${_var} ${_arg} )
+ endif()
+
+ endforeach( )
+
+ # select a tool for merging desktop file translations
+ if( NOT MSGFMT_EXECUTABLE OR NOT MSGFMT_VERSION )
+ tde_setup_msgfmt( )
+ endif( )
+ if( "${MSGFMT_VERSION}" VERSION_LESS "0.19" )
+ if( NOT INTLTOOL_MERGE_EXECUTABLE )
+ find_program( INTLTOOL_MERGE_EXECUTABLE
+ NAMES intltool-merge
+ HINTS "${TDE_PREFIX}/bin"
+ )
+ if( "${INTLTOOL_MERGE_EXECUTABLE}" STREQUAL "INTLTOOL_MERGE_EXECUTABLE-NOTFOUND" )
+ tde_message_fatal( "xgettext >= 0.19 or intltool-merge is required but not found" )
+ endif( )
+ endif( )
+ set( DESKTOP_MERGE_INTLTOOL 1 )
+ else( )
+ set( DESKTOP_MERGE_MSGFMT 1 )
+ endif( )
+
+ # pick keywords
+ unset( _keywords_desktop )
+ foreach( _keyword ${_keywords_desktop_default} ${_keywords_add} )
+ if( "${_keyword}" STREQUAL "-" )
+ unset( _keywords_desktop )
+ unset( _keyword )
+ endif( )
+ if( _keyword )
+ list( APPEND _keywords_desktop "${_keyword}" )
+ endif( )
+ endforeach( )
+
+ # no source file specified!
+ if( NOT _src )
+ tde_message_fatal( "no source desktop file specified" )
+ endif( )
+ get_filename_component( _basename ${_src} NAME )
+
+ # if no output name specified, use the same as source
+ if( NOT _out_name )
+ get_filename_component( _out_name ${_src} NAME )
+ endif( )
+
+ # if no po directory specified, try to determine it
+ if( NOT _po_dir )
+ if( EXISTS ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_basename} AND
+ IS_DIRECTORY ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_basename} )
+ set( _po_dir ${CMAKE_SOURCE_DIR}/translations/desktop_files/${_basename} )
+
+ elseif( EXISTS ${CMAKE_SOURCE_DIR}/po/desktop_files/${_basename} AND
+ IS_DIRECTORY ${CMAKE_SOURCE_DIR}/po/desktop_files/${_basename} )
+ set( _po_dir ${CMAKE_SOURCE_DIR}/po/desktop_files/${_basename} )
+
+ endif( )
+ endif( )
+
+ # if no destination directory specified, install as application link
+ if( NOT _dest )
+ set( _dest ${XDG_APPS_INSTALL_DIR} )
+ endif( )
+
+ # are there any translations available?
+ unset( _translations )
+ if( EXISTS "${_po_dir}" AND IS_DIRECTORY "${_po_dir}" )
+ file( GLOB _translations RELATIVE "${_po_dir}" "${_po_dir}/*.po" )
+ endif( )
+ if( _translations )
+ if( DESKTOP_MERGE_MSGFMT )
+
+ # create LINGUAS file for msgfmt
+ string( REPLACE ".po;" "\n" _linguas "${_translations};" )
+ file( WRITE ${_po_dir}/LINGUAS "${_linguas}" )
+
+ # prepare keywords for msgfmt
+ set( _keywords_arg "--keyword=" )
+ foreach( _keyword ${_keywords_desktop} )
+ list( APPEND _keywords_arg "--keyword=\"${_keyword}\"" )
+ endforeach( )
+
+ # merge translations
+ get_filename_component( _src ${_src} ABSOLUTE )
+ add_custom_command(
+ OUTPUT ${_out_name}
+ COMMAND ${MSGFMT_EXECUTABLE} --desktop --template ${_src} -d ${_po_dir} -o ${_out_name} ${_keywords_arg}
+ DEPENDS ${_src}
+ )
+ add_custom_target( "${_out_name}-translated" ALL DEPENDS ${_out_name} )
+ add_custom_command(
+ TARGET "${_out_name}-translated"
+ POST_BUILD COMMAND ${CMAKE_COMMAND} -E remove ${_po_dir}/LINGUAS
+ )
+ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_out_name} DESTINATION ${_dest} )
+
+ else( )
+
+ # create template for intltool-merge
+ file( READ ${_src} _src_data )
+ string( REPLACE ";" "|" _keywords_match "(${_keywords_desktop})" )
+ string( REGEX REPLACE "(^|\n)${_keywords_match}=" "\\1_\\2=" _src_data "${_src_data}" )
+ file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/${_out_name}.in "${_src_data}" )
+
+ # merge translations
+ add_custom_command(
+ OUTPUT ${_out_name}
+ COMMAND ${INTLTOOL_MERGE_EXECUTABLE} -d ${_po_dir} ${_out_name}.in ${_out_name}
+ DEPENDS ${_src}
+ )
+ add_custom_target( "${_out_name}-translated" ALL DEPENDS ${_out_name} )
+ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/${_out_name} DESTINATION ${_dest} )
+
+ endif( )
+ else( )
+
+ # just install the original file without translations
+ install(
+ FILES ${CMAKE_CURRENT_SOURCE_DIR}/${_src}
+ RENAME ${_out_name}
+ DESTINATION ${_dest}
+ )
+
+ endif( )
+
+endmacro( )
+
+
+#################################################
+#####
##### tde_create_handbook
macro( tde_create_handbook )
@@ -2001,12 +2202,27 @@ macro( tde_setup_msgfmt )
if( GETTEXT_FOUND )
set( MSGFMT_EXECUTABLE ${GETTEXT_MSGFMT_EXECUTABLE}
CACHE FILEPATH "path to msgfmt executable" )
+ if( GETTEXT_VERSION_STRING )
+ set( MSGFMT_VERSION ${GETTEXT_VERSION_STRING}
+ CACHE STRING "version of msgfmt executable" )
+ endif( )
endif( GETTEXT_FOUND )
if( NOT MSGFMT_EXECUTABLE )
tde_message_fatal( "msgfmt is required but was not found on your system." )
endif( NOT MSGFMT_EXECUTABLE )
endif( )
+
+ if( NOT MSGFMT_VERSION )
+ execute_process(
+ COMMAND ${MSGFMT_EXECUTABLE} --version
+ OUTPUT_VARIABLE _msgfmt_version
+ ERROR_VARIABLE _msgfmt_version
+ )
+ string( REGEX REPLACE "^msgfmt[^\n]* ([^ ]*)\n.*" "\\1" _msgfmt_version ${_msgfmt_version} )
+ set( MSGFMT_VERSION ${_msgfmt_version}
+ CACHE STRING "version of msgfmt executable" )
+ endif( )
endmacro( )