From 6267f1249b8a46b9c3e676a55e565e080ac74b94 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 8 Apr 2014 18:05:04 +0200 Subject: [PATCH] Add script to fix up the files we pull from Transifex --- tools/fix_all_transifex_output.sh | 11 +++++++++++ tools/fix_transifex_output.sh | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100755 tools/fix_all_transifex_output.sh create mode 100755 tools/fix_transifex_output.sh diff --git a/tools/fix_all_transifex_output.sh b/tools/fix_all_transifex_output.sh new file mode 100755 index 000000000..9f4953341 --- /dev/null +++ b/tools/fix_all_transifex_output.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +SCRIPT=$(readlink -f $0) +SCRIPTPATH=`dirname $SCRIPT` +PROJECTROOT=`dirname $SCRIPTPATH` + +cd $PROJECTROOT + +find res/values-* -name "strings.xml" -type f -exec ./tools/fix_transifex_output.sh {} \; + +cd - diff --git a/tools/fix_transifex_output.sh b/tools/fix_transifex_output.sh new file mode 100755 index 000000000..fca850881 --- /dev/null +++ b/tools/fix_transifex_output.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# What we get from Transifex is unusable and needs some fixing before we're able to use +# the translations. + +FILE=$1 + +# Fix xliff tags +perl -i -pe 's/<xliff:g id=\\?"(.*?)?\\?">//g' $FILE +perl -i -pe 's/<\/xliff:g>/<\/xliff:g>/g' $FILE + +# Escape single and double quotes before and after xliff tags +perl -i -pe 's/([^\\])(["'\''])(["'\''])/xliff:g>\\\1/g' $FILE + +# Restore "<" and ">" +perl -i -pe 's/&(lt|gt);/&\1;/g' $FILE + +# -> +perl -i -pe 's/"><\/string>/"\/>/g' $FILE + +# Escape single and double quotes (but not in comments or the xml tag) +perl -i -pe 's/([^\\])'\''/\1\\'\''/g unless /(