2012-12-30 14:34:35 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2013-01-02 09:19:04 +00:00
|
|
|
outdir=$1
|
|
|
|
|
|
|
|
if [ -z "$outdir" ] || [ "$outdir" = "." ] || [ ! -d $outdir ]; then
|
|
|
|
echo "No existing output directory provided; syntax is : $0 output_directory"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
|
2013-01-02 10:23:29 +00:00
|
|
|
linguas="en fr"
|
2012-12-30 14:34:35 +00:00
|
|
|
|
2012-12-30 21:56:13 +00:00
|
|
|
categories="defi free lost perso proto"
|
|
|
|
for sc_i in $(seq 1 9); do
|
|
|
|
categories="$categories scene$sc_i"
|
|
|
|
done
|
|
|
|
for tr_i in $(seq 1 7); do
|
|
|
|
categories="$categories train$tr_i"
|
|
|
|
done
|
|
|
|
# Empty categories: "win"
|
2012-12-30 21:23:43 +00:00
|
|
|
|
2013-01-02 09:35:15 +00:00
|
|
|
common_i18n_ext=xhtml
|
2012-12-30 14:34:35 +00:00
|
|
|
|
|
|
|
gen_i18n_file () {
|
|
|
|
|
|
|
|
levelfileorig=$1
|
2013-01-02 09:35:15 +00:00
|
|
|
common_i18n_file=$2
|
2012-12-30 14:34:35 +00:00
|
|
|
|
|
|
|
if [ -z "$levelfileorig" ] || [ ! -f $levelfileorig ]; then
|
|
|
|
echo "No file name provided; syntax is : $0 filename.txt"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
|
2013-01-02 09:35:15 +00:00
|
|
|
levelfile=$(echo $levelfileorig | sed -e "s/\.txt$//g")
|
|
|
|
|
2013-01-02 10:23:29 +00:00
|
|
|
destfile=$levelfile.xml;
|
|
|
|
allsfile=$common_i18n_file.$common_i18n_ext;
|
|
|
|
|
|
|
|
echo "<$levelfile>" > $destfile
|
|
|
|
echo "<h1><!-- Level: $levelfile --></h1>" >> $allsfile
|
|
|
|
for key in Title Resume ScriptName; do
|
|
|
|
for subkey in text resume; do
|
|
|
|
subval=$(grep "^$key\.E.*$subkey" $levelfileorig | sed -e "s/^.*$subkey=\"\([^\"]*\)\".*$/\1/")
|
|
|
|
# Always write entries, even when empty, otherwise breaks po4a-gettextize
|
|
|
|
echo "<${key}_$subkey>$levelfile:$subval</${key}_$subkey>" >> $destfile
|
|
|
|
echo "<p type=\"$key $subkey\">$levelfile:$subval</p>" >> $allsfile
|
2012-12-30 14:34:35 +00:00
|
|
|
done
|
|
|
|
done
|
2013-01-02 10:23:29 +00:00
|
|
|
echo "</$levelfile>" >> $destfile
|
2012-12-30 14:34:35 +00:00
|
|
|
|
2013-01-02 09:35:15 +00:00
|
|
|
echo "[type:xml] $levelfile.xml \$lang:$levelfile.\$lang.xml" >> $common_i18n_file-po4a.cfg
|
2012-12-30 14:34:35 +00:00
|
|
|
|
|
|
|
echo -n "."
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "* Cleanup"
|
|
|
|
|
|
|
|
|
2012-12-30 21:23:43 +00:00
|
|
|
for category in $categories; do
|
|
|
|
echo "* Category: $category "
|
2012-12-30 14:34:35 +00:00
|
|
|
|
2013-01-02 10:23:29 +00:00
|
|
|
rm -f $category*.xml
|
|
|
|
rm -f $category-po4a.cfg
|
|
|
|
|
2013-01-02 09:24:46 +00:00
|
|
|
echo " 0 - Create initial files"
|
2012-12-30 14:34:35 +00:00
|
|
|
|
2012-12-30 21:23:43 +00:00
|
|
|
echo "[po_directory] $category-po/" > $category-po4a.cfg
|
|
|
|
mkdir -p $category-po
|
2012-12-30 14:34:35 +00:00
|
|
|
|
2013-01-02 09:24:46 +00:00
|
|
|
echo -n " 1 - Generate transitional source translation files from level files"
|
2012-12-30 21:23:43 +00:00
|
|
|
|
2013-01-02 09:35:15 +00:00
|
|
|
echo "<html><body>" > $category.$common_i18n_ext
|
|
|
|
for lang in $linguas; do
|
2012-12-30 21:23:43 +00:00
|
|
|
if [ $lang = "en" ]; then continue; fi;
|
2013-01-02 09:35:15 +00:00
|
|
|
echo "<html><body>" > $category.$lang.$common_i18n_ext
|
2012-12-30 21:23:43 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
for level in $(ls $category*.txt); do
|
|
|
|
gen_i18n_file $level $category
|
|
|
|
done
|
2013-01-02 09:35:15 +00:00
|
|
|
echo "</body></html>" >> $category.$common_i18n_ext
|
2012-12-30 21:23:43 +00:00
|
|
|
|
2013-01-02 09:24:46 +00:00
|
|
|
echo "done"
|
2012-12-30 21:23:43 +00:00
|
|
|
|
2013-01-02 09:24:46 +00:00
|
|
|
echo -n " 3 - Generate pristine potfile: "
|
2013-01-02 09:35:15 +00:00
|
|
|
po4a-gettextize -M UTF-8 -f xhtml -m $category.$common_i18n_ext > $category-po/$category.pot 2>/dev/null
|
2012-12-30 21:23:43 +00:00
|
|
|
echo "done"
|
|
|
|
|
2013-01-02 09:24:46 +00:00
|
|
|
echo -n " 4 - Generate translation files: "
|
2013-01-02 09:35:15 +00:00
|
|
|
for lang in $linguas; do
|
2012-12-30 21:23:43 +00:00
|
|
|
if [ $lang = "en" ]; then continue; fi;
|
2012-12-30 21:31:18 +00:00
|
|
|
echo -n "$lang "
|
2013-01-02 09:35:15 +00:00
|
|
|
echo "</body></html>" >> $category.$lang.$common_i18n_ext
|
2012-12-30 21:23:43 +00:00
|
|
|
pofile=$category-po/$lang.po
|
|
|
|
if [ ! -f $pofile ]; then
|
2013-01-02 10:23:29 +00:00
|
|
|
sed -e 's/charset=CHARSET/charset=UTF-8/g' $category-po/$category.pot > $pofile
|
2012-12-30 21:23:43 +00:00
|
|
|
fi
|
2013-01-02 10:23:29 +00:00
|
|
|
po4a-updatepo -M UTF-8 -f xhtml -m $category.$common_i18n_ext -p $pofile 2>/dev/null
|
2012-12-30 21:23:43 +00:00
|
|
|
done
|
|
|
|
echo " done"
|
|
|
|
|
2013-01-02 09:24:46 +00:00
|
|
|
echo -n " 5 - Cleanup po4a infrastructure, run po4a … "
|
2012-12-30 21:23:43 +00:00
|
|
|
po4a -f $category-po4a.cfg 2>/dev/null 1>&2
|
|
|
|
echo "done"
|
|
|
|
|
2013-01-02 10:23:29 +00:00
|
|
|
echo -n " 6 - Inject translation in level files: "
|
|
|
|
|
|
|
|
for levelfile in $(ls $category*.txt); do
|
|
|
|
# Always start afresh
|
|
|
|
rm -f $outdir/$levelfile
|
|
|
|
|
|
|
|
rootfilename=$(echo $levelfile | sed 's/\.txt$//g')
|
|
|
|
for lang in $linguas; do
|
|
|
|
dotlang=".$lang"
|
|
|
|
langcode="";
|
|
|
|
case $lang in
|
|
|
|
en) dotlang=""; langcode=".E";;
|
|
|
|
fr) langcode=".F";;
|
|
|
|
pl) langcode=".P";;
|
|
|
|
esac
|
|
|
|
xmlfile=$rootfilename$dotlang.xml
|
|
|
|
echo -n "."
|
|
|
|
if [ -f $xmlfile ]; then
|
|
|
|
for key in Title Resume ScriptName; do
|
|
|
|
lineend=""
|
|
|
|
for subkey in text resume; do
|
|
|
|
keyval=$(grep "^<${key}_${subkey}>" $xmlfile | sed -e "s|^<${key}\_${subkey}>${rootfilename}:\(.*\)<\/${key}\_${subkey}>$|\1|g")
|
|
|
|
if [ -n "$keyval" ]; then
|
|
|
|
lineend="$lineend $subkey=\"$keyval\""
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -n "$lineend" ]; then
|
|
|
|
echo "$key$langcode$lineend" >> $outdir/$levelfile
|
2012-12-30 14:34:35 +00:00
|
|
|
fi
|
|
|
|
done
|
2013-01-02 10:23:29 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
sed -e '/^Title/d;/^Resume/d;/^ScriptName/d' $levelfile >> $outdir/$levelfile
|
2012-12-30 14:34:35 +00:00
|
|
|
done
|
2013-01-02 10:23:29 +00:00
|
|
|
echo "done."
|
2012-12-30 14:34:35 +00:00
|
|
|
done
|