#! /bin/sh

#
# See setup for user tweakables.
#
. ./setup
. $OOBUILDDIR/*.[sS]et.sh
. ./setup

primary_lang="en-US"
extra_options=

usage()
{
    echo "This script extracts localized strings in to the GSI file"
    echo
    echo "Usage:" ${0##*/} [-d] locale gsi_file
    echo
    echo "Options:"
    echo "	-d	 use default date in extracted sdf file"
    echo "	locale   locale id of the language, e.g. en-US"
    echo "      gsi_file output file"
    echo
    echo "Presumptions:"
    echo "	- the module transex3 is built"
    echo
    echo "Note that the script is quite slow. It takes some minutes to extract strings"
    echo "for one localization..."
}

test "$1" = "--help" && usage && exit 1;

test "$1" = "-d" && extra_options="-d" && shift
locale="$1"
gsi_file="$2"

if test -z "$locale" ; then
    echo "Error: locale is not defined, try --help"
    exit 1;
fi

if test -z "$locale" ; then
    echo "Error: output gsi file is not defined, try --help"
    exit 1;
fi

if ! which localize >/dev/null 2>&1 ; then
    echo "Error: Unable to find the script \"localize\". Please, build and deliver"
    echo "       the module transex3."
    exit 1;
fi

if ! echo "$2" | grep -q "^/" ; then
    gsi_file=`pwd`/$gsi_file
fi

cd $OOBUILDDIR
localize -e -f "$gsi_file" -l "$locale=$primary_lang" $extra_options
cd -
