Guest User

tf.sh

a guest
Mar 24th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.33 KB | None | 0 0
  1. #/bin/bash -
  2.  
  3. # This script is a tool to download and upload PO file from/to Transifex (www.transifex.com).
  4. # Requirements:
  5. # - You MUST have a functional Transifex account
  6. # - You MUST have curl installed
  7. #
  8. # Type in "<scriptname> HELP" for the syntax.
  9.  
  10. # This script is licensed under the MIT License.
  11.  
  12. #### CONFIG OPTIONS ####
  13.  
  14. USER=your_username_goes_here
  15. PASSWORD=your_password_goes_here
  16. FILENAME=download.po
  17.  
  18. #### END OF CONFIG OPTIONS ####
  19.  
  20. # Start of the "real" script
  21.  
  22. # Some sanity checks
  23. if [[ -z $FILENAME ]]
  24. then
  25.     echo "ERROR: FILENAME not set. Please edit the script first!"
  26.     exit
  27. fi
  28. if [[ -z $USER || -z $PASSWORD ]]
  29. then
  30.     echo "ERROR: USER or PASSWORD not set. Please edit the script first!"
  31.     exit
  32. fi
  33.  
  34. # Operation modes
  35.  
  36. # GET: Download PO file
  37. if [[ $1 == "GET" ]]
  38. then
  39.     if [[ -n $2 && -n $3 ]]
  40.     then
  41.         echo "Downloading to $FILENAME ..."
  42.         curl -L --user $USER:$PASSWORD -X GET https://www.transifex.com/api/2/project/$2/resource/$3/translation/de?file=po -o $FILENAME
  43.     else
  44.         echo "ERROR: Missing argument(s)"
  45.     fi
  46. # GETRES: Get list of resources of a project
  47. elif [[ $1 == "GETRES" ]]
  48. then
  49.     if [[ -n $2 ]]
  50.     then
  51.         curl -L --user $USER:$PASSWORD -X GET https://www.transifex.com/api/2/project/$2/resources
  52.     else
  53.         echo "ERROR: Missing argument"
  54.     fi
  55. # PUT: Upload PO file
  56. elif [[ $1 == "PUT" ]]
  57. then
  58.     if [[ -n $2 && -n $3 ]]
  59.     then
  60.         if [[ -a $FILENAME ]]
  61.         then
  62.             echo "Uploading $FILENAME ..."
  63.             curl -L --user $USER:$PASSWORD -F file=@$FILENAME -X PUT https://www.transifex.com/api/2/project/$2/resource/$3/translation/de/
  64.         else
  65.             echo "ERROR: File $FILENAME does not exist."
  66.         fi
  67.     else
  68.         echo "ERROR: Missing argument(s)"
  69.     fi
  70. # Print help
  71. elif [[ $1 == "HELP" ]]
  72. then
  73.     echo "This is a script to help you upload and download PO files from Transifex."
  74.     echo "Syntax:"
  75.     echo "  $0 HELP: Show help"
  76.     echo "  $0 GETRES <project>: List all resources of given project"
  77.     echo "  $0 GET <project> <resource>: Download PO file to download.po from given project and resource"
  78.     echo "  $0 PUT <project> <resource>: Upload download.po in working directory to given project and resource"
  79.     echo "Note: <project> and <resource> arguments need to be so-called 'slugs' (unique project/resource identifiers, as written in the URL)."
  80. else
  81.     echo "Error! Invalid mode. Use '$0 HELP' for help."
  82. fi
Advertisement
Add Comment
Please, Sign In to add comment