#emulation of gettext by j00zek 2010
#>>>>>>>>>>>>please note: "  signs and other special meaning characters for sed (e.g. * ^)
#							cannot be used in translated texts
#needed to properly translate messages
#the structure of the po file should be like following
#msgid "test 2 translate"
#msgstr "translated text"
#most important is, that msgstr has to be next to the msgid. No empty lines between allowed
#please inlude this script at the begining of yours to start using gettext("text") command
#Usage example: echo $(translate "A kuku")
#or as a separate script - as you wish ;-)
#language initialization

lang=`cat /var/tuxbox/config/neutrino.conf | grep language | cut -d'=' -f2`

#if German no translation needed
if [ "$lang" = "deutsch" ]; then echo "$1" ; exit 0 ; fi

#if current language not set, no translation at all
if [ "$lang" = "" ]; then echo "$1" ; exit 0 ; fi

langfile="/usr/share/tuxbox/neutrino/locale/$lang.po"
#langfile="/var/bin/$lang.po"

#if no language file, no translation at all
if [ ! -e "$langfile" ]; then echo "$1" ; exit 0 ; fi

translate() {
	# let's cheat a little bit ;) instead of using special chars, let's use wildcard for searching
	local text=$(echo "$1" | tr '/' '.' | tr '*' '.')
	local search='/msgid[ ]*"'$text'"/{n;p;}'
	# the funny thing is that using below structure, we can use special characters in translations :D
	local translated_text=`sed -n "$search" <$langfile  | cut -d '"' -f2`
	if [ ! "$translated_text" ]; then translated_text="$1"; fi
	echo $translated_text
}

echo "$(translate "$1")"
