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
@ -28,6 +29,7 @@ function usage() {
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
if [ ! "$option_silent" = "Y" ]; then
echo "Checking if updated files are in the specified directory ..." 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
if [ ! "$option_silent" = "Y" ]; then
echo " ... they are." echo " ... they are."
fi
echo echo
fi
fi
## PAGRINDINIS CIKLAS ## PAGRINDINIS CIKLAS
for updfile in $newtrans for updfile in $newtrans
@ -93,10 +108,14 @@ if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then
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
if [ ! "$option_silent" = "Y" ]; then
echo echo
echo "File `basename $updfile` does not belong to this translation project," echo "File `basename $updfile` does not belong to this translation project,"
echo "SKIPPING..." echo "SKIPPING..."
find ${updfile}t -print find ${updfile}t -print
else
skipped_files=$(($skipped_files+1))
fi
continue continue
# o gal ir ne taip daroma # o gal ir ne taip daroma
fi fi
@ -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
if [ ! "$option_silent" = "Y" ]; then
echo echo
echo "UPDATING $trafile using translations from $upddir/$updfile as PRIMARY translations" 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 msgmerge -N -v --compendium=$tradir/${trafile}.old -o $tradir/${trafile}.new $upddir/$updfile $tpldir/$tplfile
else else
msgmerge -N -v --compendium=$tradir/${trafile}.old -o $tradir/${trafile}.new $upddir/$updfile $tpldir/$tplfile 2> /dev/null
fi
else
if [ ! "$option_silent" = "Y" ]; then
echo echo
echo "UPDATING $trafile using translations from $upddir/$updfile as SECONDARY translations" 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 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
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 done
if [ "$option_silent" = "Y" ]; then
echo
fi