2009-02-11 20:42:35 +00:00
#!/bin/bash
2009-02-09 21:47:24 +00:00
#
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
2009-02-11 20:42:35 +00:00
# Copyright 2009, Andrius Štikonas <stikonas@gmail.com>
2009-02-09 21:47:24 +00:00
#
# #
# # 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.
2009-02-13 06:06:27 +00:00
## First - the necessary checks before going into the loop
2009-02-09 21:47:24 +00:00
2009-02-13 06:06:27 +00:00
## Declaring Functions
2009-02-09 21:47:24 +00:00
function usage() {
echo "Usage `basename $0` [options] <updated-file-dir> <translations-file-tree> <translations-template-tree>"
echo
echo "Options:"
2009-02-15 13:47:09 +00:00
echo " -NS|--new-as-secondary - use newly translated file translations"
echo " as secondary (default - use the new files"
echo " as primary translations)"
2009-02-15 17:07:58 +00:00
echo " -v|--verbose - print msgmerge output"
2009-02-09 21:47:24 +00:00
exit 1
}
## PARAMETRAI
while true
do
case $1 in
2009-02-15 13:47:09 +00:00
-NS|--new-as-secondary)
option_new_as_secondary="Y"
2009-02-09 21:47:24 +00:00
shift
;;
2009-02-15 17:07:58 +00:00
-v|--verbose)
option_verbose="Y"
2009-02-11 20:42:35 +00:00
shift
;;
2009-02-09 21:47:24 +00:00
-*|--*)
usage
;;
*)
break
;;
esac
done
2009-02-13 06:06:27 +00:00
# Check and, if incorrect usage, print usage
2009-02-09 21:47:24 +00:00
if [ $# -ne 3 ]; then
usage
fi
2009-02-13 06:06:27 +00:00
## Change paths to variables
2009-02-15 13:47:09 +00:00
upd_dir=$1
tra_tree=$2
tpl_tree=$3
2009-02-09 21:47:24 +00:00
2009-02-15 17:07:58 +00:00
if [ "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
echo "Checking if updated files are in the specified directory ..."
else
2009-02-15 13:47:09 +00:00
total_files=`find $upd_dir -name "*.po" | wc -l`
2009-02-11 20:42:35 +00:00
skipped_files=0
merged_files=0
echo -ne "\r$merged_files/$total_files merged"
fi
2009-02-15 13:47:09 +00:00
newtrans=`cd $upd_dir; find . -name "*.po"`
2009-02-09 21:47:24 +00:00
if [ "$newtrans" == "" ]; then
2009-02-15 13:47:09 +00:00
echo " ... no updated files found in: $upd_dir"
2009-02-09 21:47:24 +00:00
exit 1
2009-02-11 20:42:35 +00:00
else
2009-02-15 17:07:58 +00:00
if [ "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
echo " ... they are."
echo
fi
2009-02-09 21:47:24 +00:00
fi
2009-02-13 06:06:27 +00:00
## MAIN LOOP
2009-02-09 21:47:24 +00:00
for updfile in $newtrans
do
2009-02-15 13:47:09 +00:00
if [ `cd $tpl_tree; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then
2009-02-09 21:47:24 +00:00
echo
2009-02-11 20:42:35 +00:00
echo "Strange, there is more than one template for `basename $updfile`,"
echo "cannot determine the right one,"
echo "SKIPPING..."
2009-02-13 06:06:27 +00:00
continue
2009-02-09 21:47:24 +00:00
fi
2009-02-15 13:47:09 +00:00
if [ `cd $tra_tree; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then
2009-02-09 21:47:24 +00:00
echo
2009-02-11 20:42:35 +00:00
echo "Strange, there is more than one version of translation `basename $updfile`,"
2009-02-09 21:47:24 +00:00
echo "although there is only one translation template. There might be an extra"
echo "unneeded file in your translation tree, check it out!"
2009-02-11 20:42:35 +00:00
echo "Cannot determine the right file to translate,"
echo "SKIPPING..."
2009-02-13 06:06:27 +00:00
continue
2009-02-09 21:47:24 +00:00
fi
2009-02-15 13:47:09 +00:00
if [ `cd $tpl_tree; find ${updfile}t 2> /dev/null | wc -l` -lt 1 ]; then
2009-02-15 17:07:58 +00:00
if [ "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
echo
echo "File `basename $updfile` does not belong to this translation project,"
echo "SKIPPING..."
find ${updfile}t -print
else
skipped_files=$(($skipped_files+1))
fi
continue
2009-02-13 06:06:27 +00:00
2009-02-09 21:47:24 +00:00
fi
2009-02-15 13:47:09 +00:00
if [ `cd $tra_tree; find ${updfile} 2> /dev/null | wc -l` -lt 1 ]; then
2009-02-09 21:47:24 +00:00
echo
2009-02-11 20:42:35 +00:00
echo "File `basename $updfile` is completely newly translated,"
echo "COPYING it to the appropriate place..."
#finding the appropriate
2009-02-15 13:47:09 +00:00
tplfile=`cd $tpl_tree; find ${updfile}t`
2009-02-09 21:47:24 +00:00
secdir=`dirname $tplfile`
2009-02-15 13:47:09 +00:00
cp $upd_dir/$updfile $tra_tree/$secdir/$updfile
2009-02-09 21:47:24 +00:00
fi
2009-02-13 06:06:27 +00:00
# perform msgmerge and other actions
2009-02-15 13:47:09 +00:00
trafile=`cd $tra_tree; find $updfile`
tplfile=`cd $tpl_tree; find ${updfile}t`
mv $tra_tree/$trafile $tra_tree/${trafile}.old
2009-02-09 21:47:24 +00:00
2009-02-15 13:47:09 +00:00
if [ ! "$option_new_as_secondary" = "Y" ]; then
2009-02-15 17:07:58 +00:00
if [ "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
echo
2009-02-15 13:47:09 +00:00
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
2009-02-11 20:42:35 +00:00
else
2009-02-15 13:47:09 +00:00
msgmerge -N -v --compendium=$upd_dir/$updfile -o $tra_tree/${trafile}.new $tra_tree/${trafile}.old $tpl_tree/$tplfile 2> /dev/null
2009-02-11 20:42:35 +00:00
fi
2009-02-09 21:47:24 +00:00
else
2009-02-15 17:07:58 +00:00
if [ "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
echo
2009-02-15 13:47:09 +00:00
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
2009-02-11 20:42:35 +00:00
else
2009-02-15 13:47:09 +00:00
msgmerge -N -v --compendium=$tra_tree/${trafile}.old -o $tra_tree/${trafile}.new $upd_dir/$updfile $tpl_tree/$tplfile 2> /dev/null
2009-02-11 20:42:35 +00:00
fi
2009-02-09 21:47:24 +00:00
fi
2009-02-13 06:06:27 +00:00
# delete the Rosetta/Launchpad headers, only needed if the file was imported from Rosetta
2009-02-15 13:47:09 +00:00
cat $tra_tree/${trafile}.new | sed '/X-Rosetta-Export-Date/d' > $tra_tree/$trafile
rm $tra_tree/${trafile}.new
rm $tra_tree/${trafile}.old
2009-02-09 21:47:24 +00:00
2009-02-15 17:07:58 +00:00
if [ ! "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
merged_files=$(($merged_files+1))
echo -ne "\r$merged_files/$total_files merged"
if [ ! $skipped_files -eq 0 ]; then
echo -ne ", $skipped_files skipped"
fi
fi
done
2009-02-15 17:07:58 +00:00
if [ ! "$option_verbose" = "Y" ]; then
2009-02-11 20:42:35 +00:00
echo
fi