Translation helper scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ths-scripts/autotranslate

129 lines
3.6 KiB

#!/bin/bash
#
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
#
# #
# # This script is free software; you can redistribute it and/or modify
# # it under the terms of the GNU General Public License 2 as published by
# # the Free Software Foundation.
#
# # This script is distributed in the hope that it will be useful,
# # but WITHOUT ANY WARRANTY; without even the implied warranty of
# # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# # GNU General Public License for more details.
# #
# # You should have received a copy of the GNU General Public License
# # along with this script; if not, write to the Free Software
# # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# ths-autotranslate.sh - automatically translates project files (may initialize files that have not been started to translate) using a specified compendium.
source "`dirname $0`/ths-variables"
function usage() {
echo "Usage `basename $0` [options] <translation-files> <template-files>"
echo
echo "Options:"
echo " -C|--use-compendium=some-compendium.po"
echo " - use an external compendium during the migration"
echo " -I|--initialize"
echo " - initialize new translation files"
echo " --no-wrap - do not wrap long lines"
echo " --locale=lang - set locale for newly born files"
exit 1
}
option_no_fuzzy_matching="--no-fuzzy-matching"
option_verbose="Y"
option_do_initialization="Y"
while true
do
case $1 in
-F|--use-fuzzy-matching)
option_no_fuzzy_matching=""
shift
;;
-C=*|--use-compendium=*)
option_use_own_compendium="$option_use_own_compendium --compendium=`echo $1 | sed 's/\-C=\|--use-compendium=//'`"
shift
;;
-I|--initialize)
option_do_initialization="Y"
shift
;;
--no-wrap)
option_no_wrap="--no-wrap"
shift
;;
--locale=*)
option_locale=`echo $1 | sed 's/--locale=//'`
shift
;;
--locale)
shift
if [ $# -lt 1 ]; then
usage
fi
option_locale=$1
shift
;;
-q|--quiet)
option_verbose=""
option_verbose_msgmerge="--quiet"
shift
;;
-*|--*)
usage
;;
*)
break
;;
esac
done
if [ $# -ne 2 ]; then
usage
fi
new=$1
templates=$2
if [ "$option_do_initialization" = "Y" ]; then
echo -n " ** New files will not be initialized ** "
echo
else
echo "** Initializing new files... **"
pots=`cd $templates; find . -name "*.pot"`
if [ "$pots" == "" ]; then
echo "No POT templates found in: $templates"
exit 1
fi
for pot in $pots
do
# determine pot names according to the po names
filename=`basename $pot .pot`.po
directory=`dirname $pot`
mkdir -p $new/$directory
# copy a po file if an exact match is found for it in the templates directory
if [ -f $new/$directory/$filename ]; then
echo -n "file $new/$directory/$filename already exists, skipping creation..."
echo
else
if [ ! $option_verbose ]; then
msginit $option_no_wrap --locale=$option_locale --no-translator -i $templates/$pot -o $new/$directory/$filename 2>&1 | egrep -v "^Created"
else
msginit $option_no_wrap --locale=$option_locale --no-translator -i $templates/$pot -o $new/$directory/$filename
fi
fi
done
fi
echo "** Updating files against templates (optionally with compendium)... **"
for po in `cd $new ; find . -name "*.po" | sort`
do
[ $option_verbose ] && echo -n $new/$po
msgmerge $option_verbose_msgmerge $option_no_fuzzy_matching $option_no_wrap $option_use_own_compendium --backup=off --update $new/$po $templates/${po}t
done