update_locales 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. aberr(){ printf "[\e[31mERROR\e[0m]: \e[1m%s\e[0m\n" "$*" >&2; }
  3. abinfo(){ printf "[\e[96mINFO\e[0m]: \e[1m%s\e[0m\n" "$*" >&2; }
  4. function upload_to_tx() {
  5. if ! which tx > /dev/null; then
  6. aberr "You don't have Transifex client installed. \n Run \`pip install transifex-client\` to install it."
  7. exit 1
  8. fi
  9. abinfo "Uploading to transifex..."
  10. if ! tx push -s; then
  11. aberr "Problems occurred when uploading strings to Transifex."
  12. printf "\t Either there are syntax errors in source file or you don't have permission to update the source file."
  13. exit 1
  14. fi
  15. exit 0
  16. }
  17. function validate() {
  18. ERR_LANG=""
  19. ERR_BUF=""
  20. for i in data/locale/*.ts; do
  21. if ! ERR_BUF=$(lconvert-qt5 -i "${i}" -o "/tmp/test.qm" -of qm 2>&1); then
  22. ERR_LANG+="\e[96m$(basename "${i}")\e[0m: \e[93m${ERR_BUF}\e[0m "
  23. printf "\e[31mx\e[0m"
  24. continue
  25. fi
  26. printf "\e[32m.\e[0m"
  27. done
  28. echo ""
  29. if [[ "x${ERR_LANG}" != "x" ]]; then
  30. aberr "The following files failed the validation: "
  31. echo -e "${ERR_LANG}"
  32. fi
  33. }
  34. abinfo "Checking for your environment..."
  35. if ! which lupdate-qt5 > /dev/null; then
  36. aberr "You don't seem to have Qt i18n tools installed."
  37. printf "\tUsually this comes with your Qt installation, or you need to\n"
  38. printf "\tinstall extra packages like \`qt5-tools\` or similar.\n"
  39. exit 1;
  40. fi
  41. abinfo "Scanning directories..."
  42. if test -d src/3rdparty/qt5-x11embed/3rdparty/ECM/; then
  43. # prevent from collecting strings in ECM
  44. rm -rf src/3rdparty/qt5-x11embed/3rdparty/ECM/
  45. fi
  46. if ! lupdate-qt5 -I include/ src/ plugins/ -ts data/locale/en.ts; then
  47. aberr "There are some problems when collecting the strings."
  48. exit 1
  49. fi
  50. abinfo "Validating translations..."
  51. validate
  52. abinfo "Translations successfully updated."
  53. printf "Do you want to upload translations to Transifex? [y/N]: "
  54. read -n 1 -r TX
  55. echo ""
  56. if [[ "$TX" == "y" || "$TX" == "Y" ]]; then
  57. upload_to_tx
  58. fi
  59. abinfo "No upload as required."
  60. exit 0