Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2.  
  3. tmp_file=$(mktemp)
  4.  
  5. repository_path="${1}"
  6. file_path="${repository_path}/conf/messages."
  7. docroot_path="${repository_path}/public"
  8. langs=( "en" "es" )
  9.  
  10. echo "Searching for translatable strings"
  11. find ${repository_path}/app/views -name '*.html' -exec grep -oE "@Messages\(\".+\"\)" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
  12. find ${repository_path} -name '*.java' -exec grep -oE "\(message=\".+\"\)" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
  13. find ${repository_path} -name '*.java' -exec grep -oE "Messages\.get\(\".+\"" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
  14. find ${docroot_path} -name '*.js' -exec grep -oE "i18n\.prop\(\".+\"" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
  15. find ${docroot_path} -name '*.js' -exec grep -oE "i18n\.prop\(\'.+\'" {} \; | awk -F\" '{ print $2 }' >> ${tmp_file}
  16.  
  17. # In tmp_file we should have all translatable string
  18. # now we iterate over the file and the translation files
  19. # and echo if the translation doesn't exists
  20.  
  21. output_tmp=$(mktemp)
  22. flag_fail=0
  23.  
  24. echo "Matching found translatable strings with the different languages"
  25. while read line; do
  26.     for lang in ${langs[@]}; do
  27.         grep -q ${line} ${file_path}${lang}
  28.         if [ $? -eq 1 ]; then
  29.             echo "Translation ${line} missing in ${lang}" >> ${output_tmp}
  30.             flag_fail=1
  31.         elif [ $? -eq 2 ]; then
  32.             exit "Failed to read file ${file_path}${lang}"
  33.         fi
  34.     done
  35. done < ${tmp_file}
  36.  
  37. echo "Sorting matches"
  38. sort ${output_tmp} | uniq
  39.  
  40.  
  41. for lang in ${langs[@]}; do
  42.     echo "Looking for duplicated translations in file ${file_path}${lang}"
  43.     awk -F\= '{ print $2 }' ${file_path}${lang} | sort | uniq -dc
  44. done
  45.  
  46. rm "${tmp_file}"
  47. rm "${output_tmp}"
  48.  
  49. exit ${flag_fail}