205 lines
5.9 KiB
Bash
Executable File
205 lines
5.9 KiB
Bash
Executable File
#!/bin/bash
|
|
#
|
|
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
|
|
# Copyright 2009, Andrius Štikonas <stikonas@gmail.com>
|
|
#
|
|
# #
|
|
# # 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"
|
|
|
|
if [ ! $MSGMERGE ]; then
|
|
echo -e $RED"This program needs the msgmerge utility."$ENDCOLOR
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! $DIFF ]; then
|
|
echo -e $RED"This program suggests the diff utility."$ENDCOLOR
|
|
fi
|
|
|
|
## 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"
|
|
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
|
|
;;
|
|
-*|--*)
|
|
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; find . -name "*.po"`
|
|
total_files=`echo $newtrans | wc -w`
|
|
skipped_files=0
|
|
merged_files=0
|
|
changed_files=0
|
|
|
|
|
|
if [ "$option_verbose" = "Y" ]; then
|
|
echo "Checking if updated files are in the specified directory ..."
|
|
else
|
|
echo -ne "\r$merged_files/$total_files merged"
|
|
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))
|
|
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"; find ${updfile}t`
|
|
secdir=`dirname "$tplfile"`
|
|
cp "$upd_dir/$updfile" "$tra_tree/$updfile"
|
|
svn add "$tra_tree/$updfile"
|
|
fi
|
|
|
|
# perform msgmerge and other actions
|
|
trafile=`cd "$tra_tree"; find "$updfile"`
|
|
tplfile=`cd "$tpl_tree"; 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
|
|
cat $tra_tree/${trafile}.new | sed '/X-Rosetta-Export-Date/d' > $tra_tree/$trafile
|
|
|
|
if [ $DIFF ]; then
|
|
if [ "`$DIFF $tra_tree/${trafile}.old $tra_tree/${trafile}.new`" ]; then
|
|
changed_files=$(($changed_files+1))
|
|
fi
|
|
fi
|
|
|
|
rm $tra_tree/${trafile}.old $tra_tree/${trafile}.new
|
|
|
|
merged_files=$(($merged_files+1))
|
|
if [ ! "$option_verbose" = "Y" ]; then
|
|
echo -ne "\r$merged_files/$total_files merged"
|
|
if [ $DIFF ] && [ ! $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$merged_files/$total_files merged"$ENDCOLOR
|
|
if [ $DIFF ] && [ ! $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
|