translate.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env bash
  2. function extract_pot() {
  3. pybabel extract -s --no-wrap --project="Flex" --copyright-holder="Alexandre Vicenzi" --version="2.1.0" --mapping translations/babel.cfg --output translations/messages.pot ./
  4. }
  5. function new_translation() {
  6. pybabel init --no-wrap --input-file translations/messages.pot --output-dir translations/ --locale $1 --domain messages
  7. }
  8. function update_translation() {
  9. pybabel update --no-wrap --input-file translations/messages.pot --output-dir translations/ --domain messages
  10. }
  11. function compile_translations() {
  12. pybabel compile -f --directory translations/ --domain messages
  13. }
  14. function can_run() {
  15. if ! [ -x "$(command -v pybabel)" ]; then
  16. echo "Missing translation tool. Please, install Flask-Babel to continue."
  17. echo ""
  18. echo " pip install Flask-Babel"
  19. echo ""
  20. exit 1
  21. fi
  22. }
  23. function usage {
  24. echo "Translate Flex theme tool"
  25. echo ""
  26. echo "Usage:"
  27. echo ""
  28. echo " new [language] create new translation."
  29. echo " compile compile all PO files into MO files."
  30. echo " update update all translations based on POT file."
  31. echo " extract extract all messages from templates and create the POT file."
  32. }
  33. case "$1" in
  34. "new")
  35. can_run
  36. if [ -z "$2" ]
  37. then
  38. echo "Error: missing translation code."
  39. echo ""
  40. usage
  41. exit 1
  42. else
  43. new_translation $2
  44. fi
  45. ;;
  46. "compile")
  47. can_run
  48. compile_translations
  49. ;;
  50. "update")
  51. can_run
  52. update_translation
  53. ;;
  54. "extract")
  55. can_run
  56. extract_pot
  57. ;;
  58. *)
  59. usage
  60. exit 1
  61. ;;
  62. esac