Translation helper scripts
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

197 Zeilen
6.0 KiB

#!/bin/bash
#
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
# Copyright 2009, Andrius Štikonas <andrius@stikonas.eu>
#
# #
# # 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-poupdate.sh - takes a bunch of files from a single directory and transfers the translations therein to a translation file tree;
# may use the new files either as primary, or as secondary translations.
## First - the necessary checks before going into the loop
source "$(dirname "$0")/ths-variables"
## Declaring Functions
function usage() {
echo "Usage $(basename "$0") [options] <updated-file-dir> <translations-file-tree> <translations-template-tree>"
echo
echo "Options:"
echo " -NS|--new-as-secondary - use newly translated file translations"
echo " as secondary (default - use the new files"
echo " as primary translations)"
echo " -v|--verbose - print msgmerge output"
echo " -s|--silent - print only summary"
exit 1
}
## OPTIONS
while true
do
case $1 in
-NS|--new-as-secondary)
option_new_as_secondary="Y"
shift
;;
-v|--verbose)
option_verbose="Y"
shift
;;
-s|--silent)
option_silent="Y"
shift
;;
-*)
usage
;;
*)
break
;;
esac
done
# Check and, if incorrect usage, print usage
if [ $# -ne 3 ]; then
usage
fi
## Change paths to variables
upd_dir=$1
tra_tree=$2
tpl_tree=$3
newtrans=$(cd "$upd_dir" || exit; find . -name "*.po")
total_files=$(echo "$newtrans" | wc -w)
skipped_files=0
processed_files=0
changed_files=0
if [ "$option_verbose" = "Y" ]; then
echo "Checking if updated files are in the specified directory ..."
elif [ ! "$option_silent" = "Y" ]; then
echo -ne "\r$processed_files/$total_files processed"
fi
if [ "$newtrans" == "" ]; then
echo -e "${RED}\t\t... no updated files found in: $upd_dir$ENDCOLOR"
exit 1
else
if [ "$option_verbose" = "Y" ]; then
echo " ... they are."
echo
fi
fi
## MAIN LOOP
for updfile in $newtrans
do
if [ "$(cd "$tpl_tree"; find "${updfile}t" 2> /dev/null | wc -l)" -gt 1 ]; then
if [ "$option_verbose" = "Y" ]; then
echo
echo "Strange, there is more than one template for $(basename "$updfile"),"
echo "cannot determine the right one,"
echo "SKIPPING..."
fi
continue
fi
if [ "$(cd "$tpl_tree"; find "${updfile}" 2> /dev/null | wc -l)" -gt 1 ]; then
if [ "$option_verbose" = "Y" ]; then
echo
echo "Strange, there is more than one version of translation $(basename "$updfile"),"
echo "although there is only one translation template. There might be an extra"
echo "unneeded file in your translation tree, check it out!"
echo "Cannot determine the right file to translate,"
echo "SKIPPING..."
fi
continue
fi
if [ "$(cd "$tpl_tree"; find "${updfile}t" 2> /dev/null | wc -l)" -lt 1 ]; then
if [ "$option_verbose" = "Y" ]; then
echo
echo -e "File $RED$(basename "$updfile")$ENDCOLOR does not belong to this translation project,"
echo "SKIPPING..."
find "${updfile}t" -print
fi
skipped_files=$((skipped_files+1))
processed_files=$((processed_files+1))
continue
fi
if [ "$(cd "$tra_tree"; find "$updfile" 2> /dev/null | wc -l)" -lt 1 ]; then
echo
echo -e "File $RED$(basename "$updfile")$ENDCOLOR is completely newly translated,"
echo "COPYING it to the appropriate place..."
#finding the appropriate
tplfile=$(cd "$tpl_tree" || exit; find "$updfile"t)
cp "$upd_dir/$updfile" "$tra_tree/$updfile"
svn add "$tra_tree/$updfile"
fi
# perform msgmerge and other actions
trafile=$(cd "$tra_tree" || exit; find "$updfile")
tplfile=$(cd "$tpl_tree" || exit; find "${updfile}t")
mv "$tra_tree/$trafile" "$tra_tree/${trafile}.old"
if [ ! "$option_new_as_secondary" = "Y" ]; then
if [ "$option_verbose" = "Y" ]; then
echo
echo "UPDATING $trafile using translations from $upd_dir/$updfile as SECONDARY translations"
msgmerge -N -v --compendium="$upd_dir/$updfile" -o "$tra_tree/$trafile.new" "$tra_tree/${trafile}.old" "$tpl_tree/$tplfile"
else
msgmerge -N -v --compendium="$upd_dir/$updfile" -o "$tra_tree/$trafile.new" "$tra_tree/${trafile}.old" "$tpl_tree/$tplfile" 2> /dev/null
fi
else
if [ "$option_verbose" = "Y" ]; then
echo
echo "UPDATING $trafile using translations from $upd_dir/$updfile as PRIMARY translations"
msgmerge -N -v --compendium="$tra_tree/$trafile.old" -o "$tra_tree/$trafile.new" "$upd_dir/$updfile" "$tpl_tree/$tplfile"
else
msgmerge -N -v --compendium="$tra_tree/$trafile.old" -o "$tra_tree/$trafile.new" "$upd_dir/$updfile" "$tpl_tree/$tplfile" 2> /dev/null
fi
fi
# delete the Rosetta/Launchpad headers, only needed if the file was imported from Rosetta
sed '/X-Rosetta-Export-Date/d' < "$tra_tree/$trafile.new" > "$tra_tree/$trafile"
if [ "$(diff "$tra_tree/$trafile.old" "$tra_tree/$trafile.new")" ]; then
changed_files=$((changed_files+1))
fi
rm "$tra_tree/$trafile.old" "$tra_tree/$trafile.new"
processed_files=$((processed_files+1))
if [ ! "$option_verbose" = "Y" ] && [ ! "$option_silent" = "Y" ]; then
echo -ne "\r$processed_files/$total_files processed"
if [ ! $changed_files -eq 0 ]; then
echo -ne ", $changed_files changed"
fi
if [ ! $skipped_files -eq 0 ]; then
echo -ne ", $skipped_files skipped"
fi
fi
done
echo -ne "$BLUE\r$processed_files/$total_files processed$ENDCOLOR"
if [ ! "$changed_files" -eq 0 ]; then
echo -ne "$BLUE, $changed_files changed$ENDCOLOR"
fi
if [ ! $skipped_files -eq 0 ]; then
echo -ne "$BLUE, $skipped_files skipped$ENDCOLOR"
fi
echo