view packaging/getxt-gen-l10n-array.sh @ 1331:8897c90b8166

(issue108) Remove generate_cppcheck and cppcheck target This did not work correctly. It is better just to manually execute cppcheck on the files as it gives you more control over the options.
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 15 Oct 2014 13:24:59 +0200
parents 96ecd345c961
children
line wrap: on
line source
# Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
# Software engineering by Intevation GmbH
#
# This file is Free Software under the GNU GPL (v>=2)
# and comes with ABSOLUTELY NO WARRANTY!
# See LICENSE.txt for details.
#
# Author(s):
# Sascha Wilde <wilde@intevation.de>

# 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.

# NOTE: 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
    if [ "$id" != '"$1"' ] ; then
        MSGIDS+=("$id")
    fi
  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"

http://wald.intevation.org/projects/trustbridge/