ths-scripts/poupdate

198 linhas
6.0 KiB
Plaintext

#!/bin/bash
2009-02-09 21:47:24 +00:00
#
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
2014-11-21 21:12:46 +00:00
# Copyright 2009, Andrius Štikonas <andrius@stikonas.eu>
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
#
2009-02-15 19:50:44 +00:00
# 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-09 21:47:24 +00:00
## First - the necessary checks before going into the loop
2009-02-09 21:47:24 +00:00
2021-01-29 20:05:52 +00:00
source "$(dirname "$0")/ths-variables"
2009-02-15 19:50:44 +00:00
## Declaring Functions
2009-02-09 21:47:24 +00:00
function usage() {
2021-01-29 20:05:52 +00:00
echo "Usage $(basename "$0") [options] <updated-file-dir> <translations-file-tree> <translations-template-tree>"
2009-02-09 21:47:24 +00:00
echo
echo "Options:"
echo " -NS|--new-as-secondary - use newly translated file translations"
echo " as secondary (default - use the new files"
echo " as primary translations)"
echo " -v|--verbose - print msgmerge output"
2010-09-08 18:36:08 +01:00
echo " -s|--silent - print only summary"
2009-02-09 21:47:24 +00:00
exit 1
}
2009-02-15 19:50:44 +00:00
## OPTIONS
2009-02-09 21:47:24 +00:00
while true
do
case $1 in
-NS|--new-as-secondary)
option_new_as_secondary="Y"
2009-02-09 21:47:24 +00:00
shift
;;
-v|--verbose)
option_verbose="Y"
shift
;;
2010-09-08 18:36:08 +01:00
-s|--silent)
option_silent="Y"
shift
;;
2021-01-29 20:05:52 +00:00
-*)
2009-02-09 21:47:24 +00:00
usage
;;
*)
break
;;
esac
done
# Check and, if incorrect usage, print usage
2009-02-09 21:47:24 +00:00
if [ $# -ne 3 ]; then
usage
fi
## Change paths to variables
upd_dir=$1
tra_tree=$2
tpl_tree=$3
2009-02-09 21:47:24 +00:00
2021-01-29 20:05:52 +00:00
newtrans=$(cd "$upd_dir" || exit; find . -name "*.po")
total_files=$(echo "$newtrans" | wc -w)
skipped_files=0
2010-09-08 18:13:42 +01:00
processed_files=0
changed_files=0
if [ "$option_verbose" = "Y" ]; then
echo "Checking if updated files are in the specified directory ..."
2010-09-08 18:36:08 +01:00
elif [ ! "$option_silent" = "Y" ]; then
echo -ne "\r$processed_files/$total_files processed"
fi
2009-02-09 21:47:24 +00:00
if [ "$newtrans" == "" ]; then
2021-01-29 20:05:52 +00:00
echo -e "${RED}\t\t... no updated files found in: $upd_dir$ENDCOLOR"
2009-02-09 21:47:24 +00:00
exit 1
else
if [ "$option_verbose" = "Y" ]; then
echo " ... they are."
echo
fi
2009-02-09 21:47:24 +00:00
fi
## MAIN LOOP
2009-02-09 21:47:24 +00:00
for updfile in $newtrans
do
2021-01-29 20:05:52 +00:00
if [ "$(cd "$tpl_tree"; find "${updfile}t" 2> /dev/null | wc -l)" -gt 1 ]; then
if [ "$option_verbose" = "Y" ]; then
echo
2021-01-29 20:05:52 +00:00
echo "Strange, there is more than one template for $(basename "$updfile"),"
echo "cannot determine the right one,"
echo "SKIPPING..."
fi
continue
2009-02-09 21:47:24 +00:00
fi
2021-01-29 20:05:52 +00:00
if [ "$(cd "$tpl_tree"; find "${updfile}" 2> /dev/null | wc -l)" -gt 1 ]; then
if [ "$option_verbose" = "Y" ]; then
echo
2021-01-29 20:05:52 +00:00
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..."
fi
continue
2009-02-09 21:47:24 +00:00
fi
2021-01-29 20:05:52 +00:00
if [ "$(cd "$tpl_tree"; find "${updfile}t" 2> /dev/null | wc -l)" -lt 1 ]; then
if [ "$option_verbose" = "Y" ]; then
echo
2021-01-29 20:05:52 +00:00
echo -e "File $RED$(basename "$updfile")$ENDCOLOR does not belong to this translation project,"
echo "SKIPPING..."
2021-01-29 20:05:52 +00:00
find "${updfile}t" -print
fi
2021-01-29 20:05:52 +00:00
skipped_files=$((skipped_files+1))
processed_files=$((processed_files+1))
continue
2009-02-09 21:47:24 +00:00
fi
2021-01-29 20:05:52 +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
2021-01-29 20:05:52 +00:00
echo -e "File $RED$(basename "$updfile")$ENDCOLOR is completely newly translated,"
echo "COPYING it to the appropriate place..."
#finding the appropriate
2021-01-29 20:05:52 +00:00
tplfile=$(cd "$tpl_tree" || exit; find "$updfile"t)
2010-09-08 17:46:11 +01:00
cp "$upd_dir/$updfile" "$tra_tree/$updfile"
2014-11-21 21:12:46 +00:00
svn add "$tra_tree/$updfile"
2009-02-09 21:47:24 +00:00
fi
# perform msgmerge and other actions
2021-01-29 20:05:52 +00:00
trafile=$(cd "$tra_tree" || exit; find "$updfile")
tplfile=$(cd "$tpl_tree" || exit; find "${updfile}t")
mv "$tra_tree/$trafile" "$tra_tree/${trafile}.old"
2009-02-09 21:47:24 +00:00
if [ ! "$option_new_as_secondary" = "Y" ]; then
if [ "$option_verbose" = "Y" ]; then
echo
echo "UPDATING $trafile using translations from $upd_dir/$updfile as SECONDARY translations"
2021-01-29 20:05:52 +00:00
msgmerge -N -v --compendium="$upd_dir/$updfile" -o "$tra_tree/$trafile.new" "$tra_tree/${trafile}.old" "$tpl_tree/$tplfile"
else
2021-01-29 20:05:52 +00:00
msgmerge -N -v --compendium="$upd_dir/$updfile" -o "$tra_tree/$trafile.new" "$tra_tree/${trafile}.old" "$tpl_tree/$tplfile" 2> /dev/null
fi
2009-02-09 21:47:24 +00:00
else
if [ "$option_verbose" = "Y" ]; then
echo
echo "UPDATING $trafile using translations from $upd_dir/$updfile as PRIMARY translations"
2021-01-29 20:05:52 +00:00
msgmerge -N -v --compendium="$tra_tree/$trafile.old" -o "$tra_tree/$trafile.new" "$upd_dir/$updfile" "$tpl_tree/$tplfile"
else
2021-01-29 20:05:52 +00:00
msgmerge -N -v --compendium="$tra_tree/$trafile.old" -o "$tra_tree/$trafile.new" "$upd_dir/$updfile" "$tpl_tree/$tplfile" 2> /dev/null
fi
2009-02-09 21:47:24 +00:00
fi
# delete the Rosetta/Launchpad headers, only needed if the file was imported from Rosetta
2021-01-29 20:05:52 +00:00
sed '/X-Rosetta-Export-Date/d' < "$tra_tree/$trafile.new" > "$tra_tree/$trafile"
2021-01-29 20:05:52 +00:00
if [ "$(diff "$tra_tree/$trafile.old" "$tra_tree/$trafile.new")" ]; then
changed_files=$((changed_files+1))
fi
2021-01-29 20:05:52 +00:00
rm "$tra_tree/$trafile.old" "$tra_tree/$trafile.new"
2009-02-09 21:47:24 +00:00
2021-01-29 20:05:52 +00:00
processed_files=$((processed_files+1))
2010-09-08 18:36:08 +01:00
if [ ! "$option_verbose" = "Y" ] && [ ! "$option_silent" = "Y" ]; then
2010-09-08 18:13:42 +01:00
echo -ne "\r$processed_files/$total_files processed"
2021-01-29 20:05:52 +00:00
if [ ! $changed_files -eq 0 ]; then
echo -ne ", $changed_files changed"
fi
if [ ! $skipped_files -eq 0 ]; then
echo -ne ", $skipped_files skipped"
fi
fi
done
2021-01-29 20:05:52 +00:00
echo -ne "$BLUE\r$processed_files/$total_files processed$ENDCOLOR"
if [ ! "$changed_files" -eq 0 ]; then
echo -ne "$BLUE, $changed_files changed$ENDCOLOR"
fi
if [ ! $skipped_files -eq 0 ]; then
2021-01-29 20:05:52 +00:00
echo -ne "$BLUE, $skipped_files skipped$ENDCOLOR"
fi
echo