Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/bin/bash -
- # This script is a tool to download and upload PO file from/to Transifex (www.transifex.com).
- # Requirements:
- # - You MUST have a functional Transifex account
- # - You MUST have curl installed
- #
- # Type in "<scriptname> HELP" for the syntax.
- # This script is licensed under the MIT License.
- #### CONFIG OPTIONS ####
- USER=your_username_goes_here
- PASSWORD=your_password_goes_here
- FILENAME=download.po
- #### END OF CONFIG OPTIONS ####
- # Start of the "real" script
- # Some sanity checks
- if [[ -z $FILENAME ]]
- then
- echo "ERROR: FILENAME not set. Please edit the script first!"
- exit
- fi
- if [[ -z $USER || -z $PASSWORD ]]
- then
- echo "ERROR: USER or PASSWORD not set. Please edit the script first!"
- exit
- fi
- # Operation modes
- # GET: Download PO file
- if [[ $1 == "GET" ]]
- then
- if [[ -n $2 && -n $3 ]]
- then
- echo "Downloading to $FILENAME ..."
- curl -L --user $USER:$PASSWORD -X GET https://www.transifex.com/api/2/project/$2/resource/$3/translation/de?file=po -o $FILENAME
- else
- echo "ERROR: Missing argument(s)"
- fi
- # GETRES: Get list of resources of a project
- elif [[ $1 == "GETRES" ]]
- then
- if [[ -n $2 ]]
- then
- curl -L --user $USER:$PASSWORD -X GET https://www.transifex.com/api/2/project/$2/resources
- else
- echo "ERROR: Missing argument"
- fi
- # PUT: Upload PO file
- elif [[ $1 == "PUT" ]]
- then
- if [[ -n $2 && -n $3 ]]
- then
- if [[ -a $FILENAME ]]
- then
- echo "Uploading $FILENAME ..."
- curl -L --user $USER:$PASSWORD -F file=@$FILENAME -X PUT https://www.transifex.com/api/2/project/$2/resource/$3/translation/de/
- else
- echo "ERROR: File $FILENAME does not exist."
- fi
- else
- echo "ERROR: Missing argument(s)"
- fi
- # Print help
- elif [[ $1 == "HELP" ]]
- then
- echo "This is a script to help you upload and download PO files from Transifex."
- echo "Syntax:"
- echo " $0 HELP: Show help"
- echo " $0 GETRES <project>: List all resources of given project"
- echo " $0 GET <project> <resource>: Download PO file to download.po from given project and resource"
- echo " $0 PUT <project> <resource>: Upload download.po in working directory to given project and resource"
- echo "Note: <project> and <resource> arguments need to be so-called 'slugs' (unique project/resource identifiers, as written in the URL)."
- else
- echo "Error! Invalid mode. Use '$0 HELP' for help."
- fi
Advertisement
Add Comment
Please, Sign In to add comment