wesnoth/utils/change_textdomain
2007-05-02 11:19:51 +00:00

156 lines
3.8 KiB
Bash
Executable File

#!/bin/sh
#
# change-textdomain -- hack the text domain of a specified campaign
#
# Code by Eric S. Raymond, May 2007.
#
# Ivanovic's original specification from FR #9039.
#
# would be nice to have a tool maybe named utils/textdomain2textdomain
# that is able to change the textdomain of a given campaign. The params
# that the script should support are these: campaignname,
# oldtextdomain, newtextdomain
#
# * asumptions: campaign lies in data/campaigns, current textdomain
# is wesnoth-oldtextdomain, the translation files are existing
# (and maybe already uploaded) in the folder
# /po/wesnoth-oldtextdomain/.
#
# Here is what is to be done for the campaign named 'foo' to move from
# the textdomain wesnoth-oldtextdomain to wesnoth-newtextdomain:
#
# 1) search in all files in data/campaigns/foo* (yes, the .cfg file, too)
# for this string:
#
# #textdomain wesnoth-oldtextdomain
#
# 2) replace (be aware, there might be " " around the part after name=)
#
# [textdomain]
# name=wesnoth-oldtextdomain
# [/textdomain]
#
# with
#
# [textdomain]
# name=wesnoth-newtextdomain
# [/textdomain]
#
# 3) move the folder po/wesnoth-oldtextdomain to
# po/wesnoth-newtextdomain (svn mv if the file is already under
# version conrol, normal mv if it is not)
#
# 4) move the file (folders are already changed)
# po/wesnoth-newtextdomain/wesnoth-oldtextdomain.pot to
# po/wesnoth-newtextdomain/wensoth-newtextdomain.pot (via svn mv if
# files are under version control already, --force will be needed,
# since it is a 2nd move)
#
# 5) replace wesnoth-oldtextdomain by wesnoth-newtextdomain in
# po/wesnoth-newtextdomain/Makevars
#
# 6) replace wesnoth-oldtextdomain by wesnoth-newtextdomain in po/Makefile.am
#
# 7) replace wesnoth-oldtextdomain by wesnoth-newtextdomain in configure.ac
#
usage()
{
cat <<EOF
Usage: change_textdomain {-h | campaign-name oldtextdomain newtextdomain}
Options:
-h, --help Emit this help message and quit
Requires as first argument a campaign name.
Requires as second and third arguments old and new text domain names.
Call from the top-level directory of mainline.
EOF
}
die()
{
echo "change_textdomain: $1"
exit 1
}
replace()
# Replace a specified string with another in any number of files
{
left="$1"; right="$2"; shift; shift;
for file in $*
do
if grep "$left" $file >/dev/null 2>&1
then
overwrite $file sed "s@$left@$right@g" $file
fi
done
}
overwrite()
# Replace a file with itself filtered by a command
{
opath=$PATH
PATH=/bin:usr/bin
file=$1; shift
new=/tmp/over$$; old=/tmp/under$$
trap \'rm -f $new $old ; exit 1\' 1 2 15
if PATH=$opath "$@" >$new
then
cp $file $old # save the old file
trap '' 1 2 15 # We are committed; ignore signals
cp $new $file
else
echo "overwrite: $1 failed, $file unchanged" 1 >&2
exit 1
fi
rm -f $new $old
}
svnmove()
# Move a file, whether under version control or not
{
if svn mv --force $1 $2
then
:
else
mv $1 $2
fi
}
if [ "$1" = "-h" -o "$1" = "--help" ]
then
usage
exit 1
else
campaign=$2
old=$3
new=$4
if [ $campaign == "" ]
then
usage
die "a campaign name is required."
elif [ $old = "" ]
then
usage
die "an old textdomain name is required."
elif [ $new = "" ]
then
usage
die "a new textdomain name is required."
else
# First, hack scenario and autoconf files
replace wesnoth-${old} wesnoth-${new} \
configure.ac \
po/Makefile.am \
po/wesnoth-${old}/Makevars \
data/${campaign}.cfg \
`find data/${campaign} -name "*.cfg" -print`
# Then do the .pot and folder moves
svnmove po/wesnoth-${old}/${old}.pot po/wesnoth-${old}/${new}.pot
svnmove po/wesnoth-${old} po/wesnoth-${new}
fi
fi