#!/bin/sh

if [ "$1" = '' ]
then
	echo "usage check_translation <file>"
	exit 1
fi

if [ ! -f "$1" ]
then
	echo "Translation $1 does not exist"
	exit 1
fi

default_all=$(grep -c '=' < default.toml)
default_untranslatable=$(grep -c '^#untranslatable' < default.toml)
default=$(( default_all - default_untranslatable ))

translated_all=$(grep -c '=' < "$1")
translated_untranslatable=$(grep -c '^#untranslatable' < "$1")
translated=$(( translated_all - translated_untranslatable ))

left=$(( default - translated ))

if [ "$translated_untranslatable" -ne 0 ]
then
	echo "Untranslatable strings in $1"
	status=1
fi

percent=$((translated * 100 / default))
echo "$percent% translated"

if [ $left -gt 0 ]
then
	echo "There are $left strings left to translate"
elif [ $left -eq 0 ]
then
	echo "All strings translated"
fi

exit $status
