Add -s|--silent option to suppress msgmerge output.

This commit is contained in:
Andrius Štikonas 2009-02-11 22:42:35 +02:00
parent f27a10aeea
commit ef8cd63cd2
1 changed files with 66 additions and 27 deletions

View File

@ -1,6 +1,7 @@
l#!/bin/bash #!/bin/bash
# #
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt> # 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 # # This script is free software; you can redistribute it and/or modify
@ -25,9 +26,10 @@ function usage() {
echo "Usage `basename $0` [options] <updated-file-dir> <translations-file-tree> <translations-template-tree>" echo "Usage `basename $0` [options] <updated-file-dir> <translations-file-tree> <translations-template-tree>"
echo echo
echo "Options:" echo "Options:"
echo " -P|--new-as-primary - use newly translated file translations " echo " -P|--new-as-primary - use newly translated file translations"
echo " as primary (default - use the new files" echo " as primary (default - use the new files"
echo " as secondary translations)" echo " as secondary translations)"
echo " -s|--silent - suppress msgmerge output"
exit 1 exit 1
} }
@ -39,6 +41,10 @@ do
option_new_as_primary="Y" option_new_as_primary="Y"
shift shift
;; ;;
-s|--silent)
option_silent="Y"
shift
;;
-*|--*) -*|--*)
usage usage
;; ;;
@ -58,15 +64,24 @@ upddir=$1
tradir=$2 tradir=$2
tpldir=$3 tpldir=$3
echo "Checking if updated files are in the specified directory ..." if [ ! "$option_silent" = "Y" ]; then
echo "Checking if updated files are in the specified directory ..."
else
total_files=`find $upddir -name "*.po" | wc -l`
skipped_files=0
merged_files=0
echo -ne "\r$merged_files/$total_files merged"
fi
newtrans=`cd $upddir; find . -name "*.po"` newtrans=`cd $upddir; find . -name "*.po"`
if [ "$newtrans" == "" ]; then if [ "$newtrans" == "" ]; then
echo " ... no updated files found in: $upddir" echo " ... no updated files found in: $upddir"
exit 1 exit 1
else else
echo " ... they are." if [ ! "$option_silent" = "Y" ]; then
echo " ... they are."
echo
fi
fi fi
echo
## PAGRINDINIS CIKLAS ## PAGRINDINIS CIKLAS
for updfile in $newtrans for updfile in $newtrans
@ -74,38 +89,42 @@ do
if [ `cd $tpldir; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then if [ `cd $tpldir; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then
echo echo
echo "Strange, there is more than one template for `basename $updfile` , " echo "Strange, there is more than one template for `basename $updfile`,"
echo "cannot determine the right one, " echo "cannot determine the right one,"
echo "SKIPPING... " echo "SKIPPING..."
# kopijuoti naują failą į vertimų medį # kopijuoti naują failą į vertimų medį
continue # o gal ir ne taip daroma continue # o gal ir ne taip daroma
fi fi
if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then
echo echo
echo "Strange, there is more than one version of translation `basename $updfile` , " 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 "although there is only one translation template. There might be an extra"
echo "unneeded file in your translation tree, check it out!" echo "unneeded file in your translation tree, check it out!"
echo "Cannot determine the right file to translate, " echo "Cannot determine the right file to translate,"
echo "SKIPPING... " echo "SKIPPING..."
# kopijuoti naują failą į vertimų medį # kopijuoti naują failą į vertimų medį
continue # o gal ir ne taip daroma continue # o gal ir ne taip daroma
fi fi
if [ `cd $tpldir; find ${updfile}t 2> /dev/null | wc -l` -lt 1 ]; then if [ `cd $tpldir; find ${updfile}t 2> /dev/null | wc -l` -lt 1 ]; then
echo if [ ! "$option_silent" = "Y" ]; then
echo "File `basename $updfile` does not belong to this translation project, " echo
echo "SKIPPING... " echo "File `basename $updfile` does not belong to this translation project,"
find ${updfile}t -print echo "SKIPPING..."
continue find ${updfile}t -print
else
skipped_files=$(($skipped_files+1))
fi
continue
# o gal ir ne taip daroma # o gal ir ne taip daroma
fi fi
if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -lt 1 ]; then if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -lt 1 ]; then
echo echo
echo "File `basename $updfile` is completely newly translated, " echo "File `basename $updfile` is completely newly translated,"
echo "COPYING it to the appropriate place... " echo "COPYING it to the appropriate place..."
#finding the appropriate #finding the appropriate
tplfile=`cd $tpldir; find ${updfile}t` tplfile=`cd $tpldir; find ${updfile}t`
secdir=`dirname $tplfile` secdir=`dirname $tplfile`
cp $upddir/$updfile $tradir/$secdir/$updfile cp $upddir/$updfile $tradir/$secdir/$updfile
@ -117,17 +136,37 @@ fi
mv $tradir/$trafile $tradir/${trafile}.old mv $tradir/$trafile $tradir/${trafile}.old
if [ "$option_new_as_primary" = "Y" ]; then if [ "$option_new_as_primary" = "Y" ]; then
echo if [ ! "$option_silent" = "Y" ]; then
echo "UPDATING $trafile using translations from $upddir/$updfile as PRIMARY translations" echo
msgmerge -N -v --compendium=$tradir/${trafile}.old -o $tradir/${trafile}.new $upddir/$updfile $tpldir/$tplfile echo "UPDATING $trafile using translations from $upddir/$updfile as PRIMARY translations"
msgmerge -N -v --compendium=$tradir/${trafile}.old -o $tradir/${trafile}.new $upddir/$updfile $tpldir/$tplfile
else
msgmerge -N -v --compendium=$tradir/${trafile}.old -o $tradir/${trafile}.new $upddir/$updfile $tpldir/$tplfile 2> /dev/null
fi
else else
echo if [ ! "$option_silent" = "Y" ]; then
echo "UPDATING $trafile using translations from $upddir/$updfile as SECONDARY translations" echo
msgmerge -N -v --compendium=$upddir/$updfile -o $tradir/${trafile}.new $tradir/${trafile}.old $tpldir/$tplfile echo "UPDATING $trafile using translations from $upddir/$updfile as SECONDARY translations"
msgmerge -N -v --compendium=$upddir/$updfile -o $tradir/${trafile}.new $tradir/${trafile}.old $tpldir/$tplfile
else
msgmerge -N -v --compendium=$upddir/$updfile -o $tradir/${trafile}.new $tradir/${trafile}.old $tpldir/$tplfile 2> /dev/null
fi
fi fi
cat $tradir/${trafile}.new | sed '/X-Rosetta-Export-Date/d' > $tradir/$trafile cat $tradir/${trafile}.new | sed '/X-Rosetta-Export-Date/d' > $tradir/$trafile
rm $tradir/${trafile}.new rm $tradir/${trafile}.new
rm $tradir/${trafile}.old rm $tradir/${trafile}.old
done if [ "$option_silent" = "Y" ]; then
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
if [ "$option_silent" = "Y" ]; then
echo
fi