check_translation 830 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. if [ "$1" = '' ]
  3. then
  4. echo "usage check_translation <file>"
  5. exit 1
  6. fi
  7. if [ ! -f "$1" ]
  8. then
  9. echo "Translation $1 does not exist"
  10. exit 1
  11. fi
  12. default_all=$(grep -c '=' < default.toml)
  13. default_untranslatable=$(grep -c '^#untranslatable' < default.toml)
  14. default=$(( default_all - default_untranslatable ))
  15. translated_all=$(grep -c '=' < "$1")
  16. translated_untranslatable=$(grep -c '^#untranslatable' < "$1")
  17. translated=$(( translated_all - translated_untranslatable ))
  18. left=$(( default - translated ))
  19. if [ "$translated_untranslatable" -ne 0 ]
  20. then
  21. echo "Untranslatable strings in $1"
  22. status=1
  23. fi
  24. percent=$((translated * 100 / default))
  25. echo "$percent% translated"
  26. if [ $left -gt 0 ]
  27. then
  28. echo "There are $left strings left to translate"
  29. elif [ $left -eq 0 ]
  30. then
  31. echo "All strings translated"
  32. fi
  33. exit $status