Locale: update tool to update translations

This finishes the transition from the txgh bridge to using the transifex client to download translations and update them in the github repository. A BOINC developer needs to have write access to the github repository and must be a maintainer of the transifex project.
Don't forget to initialize the transifex client with the transifex credentials (http://docs.transifex.com/client/init/) before first use of the script.
This commit is contained in:
Christian Beer 2016-11-16 21:59:04 +01:00
parent 11bb60d4b6
commit 31a466883b
2 changed files with 60 additions and 98 deletions

3
.gitignore vendored
View File

@ -87,6 +87,9 @@ drupal/sites/default/dbconfig.php
# ignore symlink to project-specific content (tracked in separate/project repo)
drupal/sites/default/project
## translation system
locale/*/*.flag
.libs/
svn_version.h

View File

@ -1,115 +1,74 @@
#!/bin/sh
#!/bin/bash
# Look for .po files modified later than .mo, and regenerate .mo file
set -e # abort if a command exits non-zero
# update localization files from transifex and compile .po to .mo if needed
# .po files are only updated if they are 100% translated, outdated files are not removed!
# Then commit and push changes.
projname=boinc
projdir=/home/boincadm/rwalton/$projname/locale
testmode=0
if test $# -gt 0; then
if test $1 = "-t"; then
testmode=1
else
echo "Usage: $0 [-t]"
echo " -t testmode (don't commit or push to git repository)"
exit 1
fi
fi
cd $projdir
for file in `find -name 'BOINC-Manager.po'` ; do
dir=`dirname $file`
locale=`basename $dir`
template_name=BOINC-Manager
cd $projdir/${locale}
if test ${template_name}.po -nt ${template_name}.mo.flag
then
# Compile the PO file into an MO file.
pocompile ${template_name}.po ${template_name}.mo
# Add the updated file to git
git add ${template_name}.mo
# Touch each file to adjust timestamps
touch ${template_name}.po
touch ${template_name}.mo.flag
fi
# find source root upward from CWD
while ! test -r .tx/config; do
cd ..
test "`pwd`" = "/" && echo "no source directory found" >&2 && exit
done
command -v pocompile >/dev/null 2>&1 || { echo >&2 "pocompile (translate-toolkit) is needed but not installed. Aborting."; exit 1; }
command -v tx >/dev/null 2>&1 || { echo >&2 "tx (transifex-client) is needed but not installed. Aborting."; exit 1; }
cd $projdir
# check if working directory is clean to ensure we only commit localization changes
if test 0 -ne `git status -s -uno |wc -l`; then
echo "Please commit your pending changes first"
exit 1
fi
for file in `find -name 'BOINC-Client.po'` ; do
dir=`dirname $file`
locale=`basename $dir`
template_name=BOINC-Client
echo "pulling translations from transifex"
# this only updates existing languages, new languages need to be added manually with 'tx pull -a' and 'git add'
tx pull
cd $projdir/${locale}
if test ${template_name}.po -nt ${template_name}.mo.flag
then
echo "compiling localization files for Manager and Client"
srcdir=`pwd`
cd ${srcdir}/locale
# Compile the PO file into an MO file.
pocompile ${template_name}.po ${template_name}.mo
templates=("BOINC-Manager" "BOINC-Client" "BOINC-Setup" "BOINC-Web")
# Add the updated file to git
git add ${template_name}.mo
# Touch each file to adjust timestamps
touch ${template_name}.po
touch ${template_name}.mo.flag
for template_name in "${templates[@]}"; do
for file in `find -name "${template_name}.po"`; do
dir=`dirname $file`
locale=`basename $dir`
fi
cd ${srcdir}/locale/${locale}
if test ${template_name}.po -nt ${template_name}.mo.flag || test ! -e ${template_name}.mo.flag; then
# Compile the PO file into an MO file.
pocompile ${template_name}.po ${template_name}.mo
# Touch each file to adjust timestamps
touch ${template_name}.po
touch ${template_name}.mo.flag
fi
done
cd ${srcdir}/locale
done
cd ${srcdir}
cd $projdir
for file in `find -name 'BOINC-Web.po'` ; do
dir=`dirname $file`
locale=`basename $dir`
template_name=BOINC-Web
cd $projdir/${locale}
if test ${template_name}.po -nt ${template_name}.mo.flag
then
# Compile the PO file into an MO file.
pocompile ${template_name}.po ${template_name}.mo
# Add the updated file to git
git add ${template_name}.mo
# Touch each file to adjust timestamps
touch ${template_name}.po
touch ${template_name}.mo.flag
fi
done
cd $projdir
for file in `find -name 'BOINC-Setup.po'` ; do
dir=`dirname $file`
locale=`basename $dir`
template_name=BOINC-Setup
cd $projdir/${locale}
if test ${template_name}.po -nt ${template_name}.mo.flag
then
# Compile the PO file into an MO file.
pocompile ${template_name}.po ${template_name}.mo
# Add the updated file to git
git add ${template_name}.mo
# Touch each file to adjust timestamps
touch ${template_name}.po
touch ${template_name}.mo.flag
fi
done
git commit -a -m "locale: Update compiled localization files"
git push origin
git add -u # only update already tracked files (will not track new files)
if test $testmode -eq 0; then
git commit -m "Locale: Update localization files"
git push
else
echo "working directory prepared for commit, inspect changes with 'git diff --cached'"
fi
exit 0