summaryrefslogtreecommitdiffstats
path: root/tdecore/CMakeL10n.txt
diff options
context:
space:
mode:
authorSlávek Banko <slavek.banko@axis.cz>2020-11-22 20:17:07 +0100
committerSlávek Banko <slavek.banko@axis.cz>2020-11-25 14:51:55 +0100
commitcb418ed3fd61c1ab6496861df597bb1b26d412dc (patch)
tree59b5edee33514eadb9f6727d44e2664e47c3d24f /tdecore/CMakeL10n.txt
parente659dfe3b0e466f8da2dc634ed0e88d9df2e9a13 (diff)
downloadtdelibs-cb418ed3fd61c1ab6496861df597bb1b26d412dc.tar.gz
tdelibs-cb418ed3fd61c1ab6496861df597bb1b26d412dc.zip
Add CMakeL10n rules to update all_languages.desktop
according to the entry.desktop files from tde-i18n. Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'tdecore/CMakeL10n.txt')
-rw-r--r--tdecore/CMakeL10n.txt68
1 files changed, 68 insertions, 0 deletions
diff --git a/tdecore/CMakeL10n.txt b/tdecore/CMakeL10n.txt
index 88e69c56f..40fa1531b 100644
--- a/tdecore/CMakeL10n.txt
+++ b/tdecore/CMakeL10n.txt
@@ -1,3 +1,71 @@
+##### update all_languages.desktop ##############
+
+message( STATUS "Update all_languages.desktop according to the entry.desktop files from tde-i18n" )
+
+# read the current list of language codes and names
+unset( _languages_code )
+unset( _languages_name )
+file( READ ${CMAKE_CURRENT_SOURCE_DIR}/all_languages.desktop _langs_current )
+string( REGEX REPLACE "[^\n]" "" _langs_current_len "${_langs_current}" )
+string( LENGTH "+${_langs_current_len}" _langs_current_len )
+set( _langs_current_pos 0 )
+while( _langs_current_pos LESS ${_langs_current_len} )
+ string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\1" _lang_row "${_langs_current}" )
+ string( REGEX REPLACE "^([^\n]*)\n(.*)" "\\2" _langs_current "${_langs_current}" )
+ math( EXPR _langs_current_pos "${_langs_current_pos}+1" )
+ if( "${_lang_row}" MATCHES "^\\[.*\\]$" )
+ string( REGEX REPLACE "^\\[(.*)\\]$" "\\1" _lang_code ${_lang_row} )
+ endif()
+ if( (NOT "${_lang_code}" STREQUAL "") AND
+ ("${_lang_row}" MATCHES "^ *Name *=") )
+ string( REGEX REPLACE "^ *Name *= *" "" _lang_name "${_lang_row}" )
+ list( APPEND _languages_code ${_lang_code} )
+ list( APPEND _languages_name ${_lang_name} )
+ unset( _lang_code )
+ endif()
+endwhile()
+
+# merge with languages from tde-i18n entry.desktop files
+file( GLOB _languages_dirs
+ RELATIVE ${CMAKE_SOURCE_DIR}/../tde-i18n
+ ${CMAKE_SOURCE_DIR}/../tde-i18n/tde-i18n-*
+)
+foreach( _lang_dir IN LISTS _languages_dirs )
+ if( EXISTS ${CMAKE_SOURCE_DIR}/../tde-i18n/${_lang_dir}/messages/entry.desktop )
+ string( REPLACE "tde-i18n-" "" _lang_code ${_lang_dir} )
+ file( READ ${CMAKE_SOURCE_DIR}/../tde-i18n/${_lang_dir}/messages/entry.desktop _lang_name )
+ string( REGEX REPLACE "(^|.*\n) *Name *= *([^\n]*).*" "\\2" _lang_name "${_lang_name}" )
+ if( NOT "${_lang_name}" STREQUAL "" )
+ list( FIND _languages_code "${_lang_code}" _lang_index )
+ if( "${_lang_index}" GREATER -1 )
+ list( REMOVE_AT _languages_code ${_lang_index} )
+ list( REMOVE_AT _languages_name ${_lang_index} )
+ endif()
+ list( APPEND _languages_code ${_lang_code} )
+ list( APPEND _languages_name ${_lang_name} )
+ endif()
+ endif()
+endforeach()
+
+# create new all_languages.desktop
+unset( _languages )
+foreach( _lang_code IN LISTS _languages_code )
+ list( FIND _languages_code "${_lang_code}" _lang_index )
+ list( GET _languages_name ${_lang_index} _lang_name )
+ list( APPEND _languages "${_lang_code}: ${_lang_name}" )
+endforeach()
+if( _languages )
+ unset( _all_languages )
+ list( SORT _languages )
+ foreach( _lang IN LISTS _languages )
+ string( REGEX REPLACE "^([^:]*): (.*)" "\\1" _lang_code ${_lang} )
+ string( REGEX REPLACE "^([^:]*): (.*)" "\\2" _lang_name ${_lang} )
+ set( _all_languages "${_all_languages}[${_lang_code}]\nName=${_lang_name}\n" )
+ endforeach()
+ file( WRITE ${CMAKE_CURRENT_SOURCE_DIR}/all_languages.desktop "${_all_languages}" )
+endif()
+
+
##### create translation templates ##############
tde_l10n_create_template(