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.
## BŪTINIEJI PATIKRINIMAI PRIEŠ CIKLĄ
## FUNKCIJOS
function usage( ) {
echo " Usage `basename $0 ` [options] <updated-file-dir> <translations-file-tree> <translations-template-tree> "
echo
echo "Options:"
2009-02-11 20:42:35 +00:00
echo " -P|--new-as-primary - use newly translated file translations"
2009-02-09 21:47:24 +00:00
echo " as primary (default - use the new files"
echo " as secondary translations)"
2009-02-11 20:42:35 +00:00
echo " -s|--silent - suppress msgmerge output"
2009-02-09 21:47:24 +00:00
exit 1
}
## PARAMETRAI
while true
do
case $1 in
-P| --new-as-primary)
option_new_as_primary = "Y"
shift
; ;
2009-02-11 20:42:35 +00:00
-s| --silent)
option_silent = "Y"
shift
; ;
2009-02-09 21:47:24 +00:00
-*| --*)
usage
; ;
*)
break
; ;
esac
done
# PATIKRINIMAS IR NAUDOJIMO PRANEŠIMAS
if [ $# -ne 3 ] ; then
usage
fi
## KELIŲ INTERPRETAVIMAS
upddir = $1
tradir = $2
tpldir = $3
2009-02-11 20:42:35 +00:00
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
2009-02-09 21:47:24 +00:00
newtrans = ` cd $upddir ; find . -name "*.po" `
if [ " $newtrans " = = "" ] ; then
echo " ... no updated files found in: $upddir "
exit 1
2009-02-11 20:42:35 +00:00
else
if [ ! " $option_silent " = "Y" ] ; then
echo " ... they are."
echo
fi
2009-02-09 21:47:24 +00:00
fi
## PAGRINDINIS CIKLAS
for updfile in $newtrans
do
if [ ` cd $tpldir ; find ${ updfile } t 2> /dev/null | wc -l` -gt 1 ] ; then
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-09 21:47:24 +00:00
# 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
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-09 21:47:24 +00:00
# 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
2009-02-11 20:42:35 +00:00
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
2009-02-09 21:47:24 +00:00
# o gal ir ne taip daroma
fi
if [ ` cd $tradir ; find ${ updfile } 2> /dev/null | wc -l` -lt 1 ] ; then
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-09 21:47:24 +00:00
tplfile = ` cd $tpldir ; find ${ updfile } t`
secdir = ` dirname $tplfile `
cp $upddir /$updfile $tradir /$secdir /$updfile
fi
# atlikti msgmerge ir kitus veiksmus
trafile = ` cd $tradir ; find $updfile `
tplfile = ` cd $tpldir ; find ${ updfile } t`
mv $tradir /$trafile $tradir /${ trafile } .old
if [ " $option_new_as_primary " = "Y" ] ; then
2009-02-11 20:42:35 +00:00
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
2009-02-09 21:47:24 +00:00
else
2009-02-11 20:42:35 +00:00
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
2009-02-09 21:47:24 +00:00
fi
cat $tradir /${ trafile } .new | sed '/X-Rosetta-Export-Date/d' > $tradir /$trafile
rm $tradir /${ trafile } .new
rm $tradir /${ trafile } .old
2009-02-11 20:42:35 +00:00
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