aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkoem <koem@petoria.de>2013-07-25 08:50:14 +0200
committerkoem <koem@petoria.de>2013-07-29 16:41:18 +0200
commitc4529fea894a3f2dc28c3d13f4cbfcd7e6466bf4 (patch)
treeab4114e60d62229e9edc8f419ad1474579451e12
parentbc584a347dc1057f0c2a151196a021463b48ab74 (diff)
downloadcgeo-c4529fea894a3f2dc28c3d13f4cbfcd7e6466bf4.zip
cgeo-c4529fea894a3f2dc28c3d13f4cbfcd7e6466bf4.tar.gz
cgeo-c4529fea894a3f2dc28c3d13f4cbfcd7e6466bf4.tar.bz2
Scripts for crowdin integration
-rw-r--r--.gitignore1
-rw-r--r--crowdin/README31
-rwxr-xr-xcrowdin/credentials.template5
-rwxr-xr-xcrowdin/download87
-rwxr-xr-xcrowdin/globals44
-rwxr-xr-xcrowdin/update28
-rwxr-xr-xcrowdin/upload39
7 files changed, 235 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 3bf3b22..20b6028 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ gen/
/tests/hs_err_pid*.log
/cgeo-calendar/local.properties
/cgeo-calendar/private.properties
+/crowdin/credentials
.directory
org.moreunit.prefs
annotation_gen/
diff --git a/crowdin/README b/crowdin/README
new file mode 100644
index 0000000..d963cbb
--- /dev/null
+++ b/crowdin/README
@@ -0,0 +1,31 @@
+INSTALLATION
+
+- create a NEW local repo from the github repo
+ -> the scripts automatically run git pull, git push, git commit
+ -> DON'T DO ANY WORK ON THIS REPO!! It will be pushed automatically!
+ -> this repo can be a copy (cp -a) from an existing one
+- copy crowdin/credentials.template to crowdin/credentials
+- edit crowdin/credentials
+ -> find the API-KEY here http://crowdin.net/project/cgeo/settings#project-settings-api
+- prepare crowdin:
+ - run update manually
+ - upload language files to crowdin (values-*/strings.xml) via upload script.
+ Maybe it is best to start with one language or two and upload more later.
+- create a cronjob to run crowdin/download every 60 mins or trigger it somehow
+- create a cronjob to run crowdin/update every 60 mins or trigger it somehow
+
+THE SCRIPTS
+
+Run all scripts from within a repo.
+
+- update: no arguments
+ -> this will upload the base language file values/strings.xml to crowdin
+
+- download: no arguments
+ -> this will download the language files from crowdin and create/update a
+ pull request if necessary
+
+- upload: languages as arguments. e.g. upload cs da de es fr hu it ja nb nl pl pt sk sl sv
+ -> this will upload translations from actual branch of the repo to crowdin.
+ crowdin files will be overwritten, not merged. To merge it is best to
+ download them first, merge, then upload.
diff --git a/crowdin/credentials.template b/crowdin/credentials.template
new file mode 100755
index 0000000..5886cd2
--- /dev/null
+++ b/crowdin/credentials.template
@@ -0,0 +1,5 @@
+# copy this file to the file "credentials" and insert the credentials
+CROWDIN_APIKEY=
+GITHUB_USER=
+GITHUB_PASSWORD=
+
diff --git a/crowdin/download b/crowdin/download
new file mode 100755
index 0000000..89483c5
--- /dev/null
+++ b/crowdin/download
@@ -0,0 +1,87 @@
+#!/bin/bash
+
+#
+#
+# This script downloads all translations from crowdin,
+# and make a pull request on github if necessary
+#
+#
+
+# see: http://crowdin.net/page/api/export
+# see: http://crowdin.net/page/api/download
+
+. "`dirname $0`/globals"
+
+BRANCH=crowdin_translations
+GITHUB_PR_TITLE="crowdin: New translations"
+PR_EXISTS=0
+DDATE=`date +"%Y-%m-%d %H:%M:%S"`
+ZIPFILE=all.zip
+
+finish () {
+ debug "cleaning up"
+ # revert everything until last commit
+ _do git branch | grep -q "\* ${BRANCH}" && ( _do git checkout . ; _do git reset ; )
+ _do git checkout master || exit 1
+ [[ -f ${ZIPFILE} ]] && _do rm "${ZIPFILE}"
+}
+
+# update master
+_do git pull upstream master || die "couldn't git pull upstream master."
+
+# check for existing PR
+_do curl -i --get "https://api.github.com/repos/cgeo/cgeo/pulls" -o "${OUT}" \
+ || die "listing pull requests failed."
+grep -q "Status: 200 OK" "${OUT}" || ( cat "${OUT}" ; die "reading list of pull requests failed." ; )
+grep -qF "${GITHUB_PR_TITLE}" "${OUT}" && PR_EXISTS=1
+
+if [ $PR_EXISTS -eq 0 ]; then
+ debug "We don't have an open Pull Request on github."
+ # remove branch if exists
+ _do git checkout master || die "Couldn't git checkout master."
+ _do git branch -D "${BRANCH}"
+else
+ debug "We have an open Pull Request on github."
+fi
+
+# prepare branch
+if git branch | grep -q "${BRANCH}"; then
+ :
+else
+ _do git branch "${BRANCH}" || die "Couldn't create branch."
+fi
+_do git checkout "${BRANCH}" || die "Couldn't switch to branch."
+
+# package the language files (allowed every 30 min)
+debug "packaging language files."
+crowdin_surf "http://api.crowdin.net/api/project/cgeo/export?key=${CROWDIN_APIKEY}"
+
+# download and unpack translations
+[[ -f ${ZIPFILE} ]] && rm ${ZIPFILE}
+_do wget "http://api.crowdin.net/api/project/cgeo/download/all.zip?key=${CROWDIN_APIKEY}" -O ${ZIPFILE} \
+ || die "crowdin download failed."
+_do unzip -o ${ZIPFILE} || die "unzip of ${ZIPFILE} failed."
+
+# check for changes
+if [ -z "`git diff`" ]; then
+ debug "no changes, finishing."
+ finish
+ exit
+fi
+
+# upload changes to github
+AMEND=""
+[[ ! -z "`git log master..${BRANCH}`" ]] && AMEND="--amend"
+_do git commit -a "${AMEND}" -m \"${GITHUB_PR_TITLE}\" || die "commit failed."
+_do git push -f origin "${BRANCH}" || die "git push failed."
+
+# create pull request
+if [ $PR_EXISTS -eq 0 ]; then
+ _do curl -i -u "${GITHUB_USER}:${GITHUB_PASSWORD}" -d \'{\"title\":\"${GITHUB_PR_TITLE}\",\"body\":\"downloaded ${DDATE}\",\"head\":\"${GITHUB_USER}:${BRANCH}\",\"base\":\"master\"}\' "https://api.github.com/repos/cgeo/cgeo/pulls" -o "${OUT}" || die "creating the pull request failed."
+ grep -q "201 Created" "${OUT}" || die "pull request not created."
+fi
+
+# clean up
+# [[ -f "${OUT}" ]] && rm "${OUT}"
+finish
+
diff --git a/crowdin/globals b/crowdin/globals
new file mode 100755
index 0000000..0efd147
--- /dev/null
+++ b/crowdin/globals
@@ -0,0 +1,44 @@
+#!/bin/bash
+
+. "`dirname $0`/credentials"
+
+OUT=/tmp/crowdin.`basename $0`.`date +%Y-%m-%d.%H:%M:%S`.out
+
+crowdin_surf () {
+ _do curl -o "${OUT}" $@ || die "curl produced an error."
+ grep -q "error" "${OUT}" && (cat "${OUT}" ; die "crowdin access failed." ; )
+ debug "crowdin answer"
+ cat "${OUT}"
+}
+
+require_tools () {
+ # code taken from backup2l
+ local NOT_AVAIL=""
+ for TOOL in $@; do
+ if [ "`which $TOOL 2> /dev/null`" == "" ]; then NOT_AVAIL="$NOT_AVAIL $TOOL"; fi
+ done
+ if [[ "$NOT_AVAIL" != "" ]]; then
+ die "The following required tool(s) cannot be found: $NOT_AVAIL"
+ fi
+}
+
+map_to_crowdin_code () {
+ CODE=$1
+ [[ "$CODE" == "es" ]] && CODE="es-ES"
+ [[ "$CODE" == "sv" ]] && CODE="sv-SE"
+ [[ "$CODE" == "pt" ]] && CODE="pt-PT"
+ echo "$CODE"
+}
+
+finish () { : ; }
+die () { for i; do debug "$i"; done; finish; exit 1; }
+debug () { echo "`date +%Y-%m-%d.%H:%M:%S` `basename $0`: $@"; }
+
+# use this function for executing commands.
+_do () { debug "$@"; eval "$@"; }
+
+require_tools git curl wget unzip
+
+git rev-parse --show-toplevel >& /dev/null || die "Please start this script from within a repo. Aborting."
+cd "`git rev-parse --show-toplevel`"
+
diff --git a/crowdin/update b/crowdin/update
new file mode 100755
index 0000000..560ca8a
--- /dev/null
+++ b/crowdin/update
@@ -0,0 +1,28 @@
+#/bin/sh
+
+#
+#
+# This script updates
+# main/res/values/strings.xml
+# and
+# cgeo-calendar/res/values/strings.xml
+# in crowdin by uploading the files from master to crowdin.
+#
+#
+
+# see: http://crowdin.net/page/api/update-file
+
+# update_file uploads the file in parameter 1 to the crowdin file name in parameter 2
+update_file() {
+ crowdin_surf -F "files[$2]=@$1" \
+ "http://api.crowdin.net/api/project/cgeo/update-file?key=${CROWDIN_APIKEY}"
+}
+
+. "`dirname $0`/globals"
+
+_do git checkout master || die "git checkout master failed."
+_do git pull upstream master || die "git pull upstream master failed."
+
+update_file main/res/values/strings.xml /cgeo/strings.xml
+update_file cgeo-calendar/res/values/strings.xml /cgeo-calendar/strings.xml
+
diff --git a/crowdin/upload b/crowdin/upload
new file mode 100755
index 0000000..43343ef
--- /dev/null
+++ b/crowdin/upload
@@ -0,0 +1,39 @@
+#/bin/sh
+
+#
+#
+# This script uploads
+# main/res/values-xx/strings.xml
+# and
+# cgeo-calendar/res/values-xx/strings.xml
+# in crowdin by uploading the files from the current branch to crowdin.
+#
+#
+
+# see:
+
+# upload_file uploads the file in parameter 1 to the crowdin file name in parameter 2
+upload_file() {
+ if [ -f "$2" ]; then
+ CROWDIN_LANG=`map_to_crowdin_code "$1"`
+ crowdin_surf \
+ -F \"files[$3]=@$2\" \
+ -F \"language=$CROWDIN_LANG\" \
+ -F \"import_eq_suggestions=1\" \
+ \"http://api.crowdin.net/api/project/cgeo/upload-translation?key=${CROWDIN_APIKEY}\"
+ else
+ debug "$2 not found."
+ fi
+}
+
+. "`dirname $0`/globals"
+
+if [ $# -eq 0 ]; then
+ debug "no languages passed - aborting."
+fi
+
+for i in $@; do
+ upload_file $i main/res/values-$i/strings.xml /cgeo/strings.xml
+ upload_file $i cgeo-calendar/res/values-$i/strings.xml /cgeo-calendar/strings.xml
+done
+