ths-scripts/potopot

57 lines
2.1 KiB
Bash
Executable File

#!/bin/bash -e
#
# Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
#
# #
# # 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-potopot.sh - converts po files to pot (template) files (basically
# strips all the translation).
if [ $# -ne 1 ]; then
echo "Usage: $(basename "$0") </directory/with/pofiles/>"
exit 1
fi
pofiles=$1
echo "This script will create a directory of pot files called "
echo "./templates/ inside the directory of the po files."
echo "Starting in three seconds..."
sleep 3
echo "Creating directory ${pofiles}/templates/ ... "
mkdir "$pofiles/templates"
sleep 1
for file in $(cd "$pofiles"; find . -name "*.po")
do
echo -n "Working on ${file}. Unwrapping..."
# unwrap messages for cleaner operation
msgmerge --no-wrap "${pofiles}/$file $pofiles/$file" -o "$pofiles/$file"
# remove the translations and creating pot files
echo "Cleaning up translations..."
msgfilter --input="$pofiles/$file" --output-file="$pofiles/templates/${file}t" --keep-header sed --expression='s/.*//' ; echo "done."
# applying some more filters via sed: remove remaining \n signs (sed 1 and 2), removing the fuzzy headers (3), removing the empty "" (4), removing the extra empty lines (5)
echo "Applying additional filter..."
cat "$pofiles/templates/${file}t" | sed -e 's/msgstr \"\\n\"/msgstr \"\"/' | \
sed -e 's/\"\\n\"/\"\"/' | \
sed -e 's/#, fuzzy//' | \
sed -e 's/^""//' | \
sed '/./,/^$/!d' > "$pofiles/templates/${file}t" ; echo "done."
echo "File ${file}t in directory templates/ created."
echo
done