#!/bin/bash
tmp_file=$(mktemp)
repository_path="${1}"
file_path="${repository_path}/conf/messages."
docroot_path="${repository_path}/public"
langs=( "en" "es" )
echo "Searching for translatable strings"
find ${repository_path}/app/views -name '*.html' -exec grep -oE "@Messages\(\".+\"\)" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
find ${repository_path} -name '*.java' -exec grep -oE "\(message=\".+\"\)" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
find ${repository_path} -name '*.java' -exec grep -oE "Messages\.get\(\".+\"" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
find ${docroot_path} -name '*.js' -exec grep -oE "i18n\.prop\(\".+\"" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
find ${docroot_path} -name '*.js' -exec grep -oE "i18n\.prop\(\'.+\'" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
# In tmp_file we should have all translatable string
# now we iterate over the file and the translation files
# and echo if the translation doesn't exists
output_tmp=$(mktemp)
flag_fail=0
echo "Matching found translatable strings with the different languages"
while read line; do
for lang in ${langs[@]}; do
grep -q ${line} ${file_path}${lang}
if [ $? -eq 1 ]; then
echo "Translation ${line} missing in ${lang}" >> ${output_tmp}
flag_fail=1
elif [ $? -eq 2 ]; then
exit "Failed to read file ${file_path}${lang}"
fi
done
done < ${tmp_file}
echo "Sorting matches"
sort ${output_tmp} | uniq
for lang in ${langs[@]}; do
echo "Looking for duplicated translations in file ${file_path}${lang}"
awk -F\= '{ print $2 }' ${file_path}${lang} | sort | uniq -dc
done
rm "${tmp_file}"
rm "${output_tmp}"
exit ${flag_fail}