Mercurial > trustbridge
diff packaging/getxt-gen-l10n-array.sh @ 795:3a9b0c75f5a6
Added i18n code and german l10n to linux installer.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Tue, 15 Jul 2014 13:24:26 +0200 |
parents | |
children | 6e300f749a6d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/packaging/getxt-gen-l10n-array.sh Tue Jul 15 13:24:26 2014 +0200 @@ -0,0 +1,57 @@ +# ------------------------------------------------------------------- +# Copyright (C) 2014 by Intevation GmbH +# Author(s): +# Sascha Wilde <wilde@intevation.de> + +# This program is free software under the GNU GPL (>=v2) +# Read the file COPYING coming with the software for details. +# ------------------------------------------------------------------- + +# Extract getxt strings from source and generate an array for usage in +# the script using our getxt function. + +# USAGE: getxt-gen-l10n-array.sh SRC ARRAYNAME ARRAYFILE +# +# Where SRC is the shell script using getxt and ARRAYFILE is +# the file to which the generated array is to be saved. +# +# ARRAYNAME is the name of the associative bash array to generate. +# +# If ARRAYFILE exists, values already defined will be preserved, +# if the MSGID still exists. + +# FIXME: we can't handle quoted quotes: "\"" -- don't use them for +# now... + +declare -a MSGIDS +declare -A L10N + +get_msgids() +{ + while read -r id ; do + MSGIDS+=("$id") + done < <( sed -n 's/.*\(getxt\|fatal\) [^"]*\("[^"]*"\).*/\2/p' "$1" | sort | uniq ) +} + +merge_l10n() +{ + for msgid in "${MSGIDS[@]}" ; do + msg=`grep -F "[${msgid}]" "$1" | sed -n 's/.*="\(.*\)"/\1/p'` + if [ "$msg" ] ; then + L10N["$msgid"]="$msg" + fi + done +} + +write_l10n_array() +{ + echo "$1=(" + for msgid in "${MSGIDS[@]}" ; do + echo " [${msgid}]=\"${L10N[$msgid]}\"" + done + echo ")" +} + +get_msgids "$1" +merge_l10n "$3" +write_l10n_array "$2" >"$3"