bernhard@1039: # Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik bernhard@1039: # Software engineering by Intevation GmbH bernhard@1039: # bernhard@1039: # This file is Free Software under the GNU GPL (v>=2) bernhard@1039: # and comes with ABSOLUTELY NO WARRANTY! bernhard@1039: # See LICENSE.txt for details. bernhard@1039: # wilde@795: # Author(s): wilde@795: # Sascha Wilde wilde@795: wilde@795: # Extract getxt strings from source and generate an array for usage in wilde@795: # the script using our getxt function. wilde@795: wilde@795: # USAGE: getxt-gen-l10n-array.sh SRC ARRAYNAME ARRAYFILE wilde@795: # wilde@795: # Where SRC is the shell script using getxt and ARRAYFILE is wilde@795: # the file to which the generated array is to be saved. wilde@795: # wilde@795: # ARRAYNAME is the name of the associative bash array to generate. wilde@795: # wilde@795: # If ARRAYFILE exists, values already defined will be preserved, wilde@795: # if the MSGID still exists. wilde@795: wilde@795: # FIXME: we can't handle quoted quotes: "\"" -- don't use them for wilde@795: # now... wilde@795: wilde@795: declare -a MSGIDS wilde@795: declare -A L10N wilde@795: wilde@795: get_msgids() wilde@795: { wilde@795: while read -r id ; do wilde@821: if [ "$id" != '"$1"' ] ; then wilde@821: MSGIDS+=("$id") wilde@821: fi wilde@795: done < <( sed -n 's/.*\(getxt\|fatal\) [^"]*\("[^"]*"\).*/\2/p' "$1" | sort | uniq ) wilde@795: } wilde@795: wilde@795: merge_l10n() wilde@795: { wilde@795: for msgid in "${MSGIDS[@]}" ; do wilde@795: msg=`grep -F "[${msgid}]" "$1" | sed -n 's/.*="\(.*\)"/\1/p'` wilde@795: if [ "$msg" ] ; then wilde@795: L10N["$msgid"]="$msg" wilde@795: fi wilde@795: done wilde@795: } wilde@795: wilde@795: write_l10n_array() wilde@795: { wilde@795: echo "$1=(" wilde@795: for msgid in "${MSGIDS[@]}" ; do wilde@795: echo " [${msgid}]=\"${L10N[$msgid]}\"" wilde@795: done wilde@795: echo ")" wilde@795: } wilde@795: wilde@795: get_msgids "$1" wilde@795: merge_l10n "$3" wilde@795: write_l10n_array "$2" >"$3"