#!/bin/bash
set -e
if test ! -z "$QTDIR" ; then
	PATH="$QTDIR/bin:$PATH" ; fi

eval last=\${$#}
for arg in $* ; do
	case "$arg" in
	*.po)
		if test "$arg" != "$last" ; then
			echo "*** invalid translation name file usage" >&2
			exit 1
		fi
		TS="$arg"
		;;
	*.ts)
		if test "$arg" != "$last" ; then
			echo "*** invalid translation name file usage" >&2
			exit 1
		fi
		TS="$arg"
		;;
	*.qm)
		echo "*** cannot use language output as argument" >&2
		exit 1
		;;
	*)
		if test "$arg" = "$last" ; then
			echo "*** no language file to add" >&2
			exit 1
		fi
		;;
	esac
done

case "$TS" in
*.ts)
	if test ! -f "$TS" ; then
		lupdate -locations none "${@:1:$(($#-1))}" -ts $TS
		git add $TS
	fi
	;;
*.po)
	LOCALE=`basename $PO .po`
	if test ! -f "$PO" ; then
		xgettext --output $PO "${@:1:$(($#-1))}"
		git add $PO		
	fi
	;;
esac

		 
