From ef8cd63cd28fb9c3eaeedf3ea7ed9726b2725422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Wed, 11 Feb 2009 22:42:35 +0200 Subject: [PATCH] Add -s|--silent option to suppress msgmerge output. --- ths-poupdate.sh | 93 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/ths-poupdate.sh b/ths-poupdate.sh index 787a080..c585694 100755 --- a/ths-poupdate.sh +++ b/ths-poupdate.sh @@ -1,6 +1,7 @@ -l#!/bin/bash +#!/bin/bash # # Copyright 2007, Donatas Glodenis +# Copyright 2009, Andrius Štikonas # # # # # This script is free software; you can redistribute it and/or modify @@ -25,9 +26,10 @@ function usage() { echo "Usage `basename $0` [options] " echo 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 secondary translations)" + echo " -s|--silent - suppress msgmerge output" exit 1 } @@ -39,6 +41,10 @@ do option_new_as_primary="Y" shift ;; + -s|--silent) + option_silent="Y" + shift + ;; -*|--*) usage ;; @@ -58,15 +64,24 @@ upddir=$1 tradir=$2 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"` if [ "$newtrans" == "" ]; then echo " ... no updated files found in: $upddir" exit 1 -else - echo " ... they are." +else + if [ ! "$option_silent" = "Y" ]; then + echo " ... they are." + echo + fi fi - echo ## PAGRINDINIS CIKLAS for updfile in $newtrans @@ -74,38 +89,42 @@ do if [ `cd $tpldir; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then echo - echo "Strange, there is more than one template for `basename $updfile` , " - echo "cannot determine the right one, " - echo "SKIPPING... " + echo "Strange, there is more than one template for `basename $updfile`," + echo "cannot determine the right one," + echo "SKIPPING..." # kopijuoti naują failą į vertimų medį continue # o gal ir ne taip daroma fi if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then 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 "unneeded file in your translation tree, check it out!" - echo "Cannot determine the right file to translate, " - echo "SKIPPING... " + echo "Cannot determine the right file to translate," + echo "SKIPPING..." # kopijuoti naują failą į vertimų medį continue # o gal ir ne taip daroma fi if [ `cd $tpldir; find ${updfile}t 2> /dev/null | wc -l` -lt 1 ]; then - echo - echo "File `basename $updfile` does not belong to this translation project, " - echo "SKIPPING... " - find ${updfile}t -print - continue + if [ ! "$option_silent" = "Y" ]; then + 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 # o gal ir ne taip daroma fi if [ `cd $tradir; find ${updfile} 2> /dev/null | wc -l` -lt 1 ]; then echo - echo "File `basename $updfile` is completely newly translated, " - echo "COPYING it to the appropriate place... " - #finding the appropriate + echo "File `basename $updfile` is completely newly translated," + echo "COPYING it to the appropriate place..." + #finding the appropriate tplfile=`cd $tpldir; find ${updfile}t` secdir=`dirname $tplfile` cp $upddir/$updfile $tradir/$secdir/$updfile @@ -117,17 +136,37 @@ fi mv $tradir/$trafile $tradir/${trafile}.old if [ "$option_new_as_primary" = "Y" ]; then - echo - 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 + if [ ! "$option_silent" = "Y" ]; then + echo + 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 - echo - 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 + if [ ! "$option_silent" = "Y" ]; then + echo + 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 cat $tradir/${trafile}.new | sed '/X-Rosetta-Export-Date/d' > $tradir/$trafile rm $tradir/${trafile}.new rm $tradir/${trafile}.old -done \ No newline at end of file +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