#!/bin/sh
# by Mark Michelsen (Skovbaer)

if [ "$2" == "" ]; then
	cat << EOF
WesLang v0.1.1 - Automatic language cfg updater/creator script
--------------------------------------------------------------
Usage: weslang [make/update] [language name e.g. danish] ([v])

   make - Creates a new basic cfg ready for translation
 update - Updates an existing cfg, adding untranslated strings
      v - Verbose compiling of tools

Note: Please be patient as the script builds the translations tools ;)
Note2: Remember to run this script from topdir (e.g. /usr/games/wesnoth) !

EOF
exit 0;
fi
if [ "$1" != "make" -a "$1" != "update" ]; then
	cat << EOF
You have to choose either 'make' or 'update'!
Run WesLang with no parameters to see an explanation.

EOF
exit 0;
fi
echo Compiling tools...
if [ "$3" == "v" ]; then
	./autogen.sh
	./configure --prefix=/usr --enable-tools
	cd src/tools
	make
else
	./autogen.sh > /dev/null
	./configure --prefix=/usr --enable-tools > /dev/null
	cd src/tools > /dev/null
	make > /dev/null
fi
cd ../..
if [ "$1" == "make" ]; then
	echo Creating data/translations/$2.cfg
	src/tools/make_translation > data/translations/$2.cfg
else
	echo Adding new strings to data/translations/$2.cfg
	src/tools/make_translation > weslang.tmp
	src/tools/merge_translations data/translations/$2.cfg weslang.tmp > $2.cfg
	rm -f weslang.tmp
	mv -f $2.cfg data/translations
fi
echo Done.
