#!/bin/bash

echo "Running translation check for lang_$1.xml"

if [ -z "$1" ]; then
	echo "Usage $0 <langcode>"
	echo "Execute in maxr src folder"
	echo "Needs xml_grep in PATH!"
	exit
fi

#parse all Text~foo~bar strings from source
{
	IFS=$'\n'
	LANGTEXT=( $(grep "Text~" *.cpp | awk -F "Text~" '{ print  $2 }' | awk -F '\"' '{ print  $1 }' | tr '~' '/') )
}

#sort and remouve doubles
TEST=( $( printf "%s\n" "${LANGTEXT[@]}" | awk 'x[$0]++ == 0' ) )


#run xml_grep to count found nodes (may need additional package installed)
for line in ${TEST[@]}; do
 	COUNT=`xml_grep --count --strict ../data/languages/lang_$1.xml --cond MAX_Language_File/Text/$line | grep total | awk '{print $2}' `
	if [ "$COUNT" -eq 0 ]; then
		echo "Missing: $line"
	fi
done

