Make automatic translation generation script slightly more robust

Setup a temporary directory to better control the complete configuration
and hopefully prevent unwanted characters in directory names.

Additionally support minetest and minetestserver executables installed to
PATH. Also support being run from anywhere and not only from tool
directory itself.

Use --quiet parameter instead of directing all output to /dev/null to
better support debugging.
This commit is contained in:
Jürgen Rühle 2024-10-14 01:09:08 +02:00
parent 6b1368d792
commit 5231b95158
5 changed files with 80 additions and 27 deletions

View File

@ -1,45 +1,92 @@
#!/bin/sh
world=mcla_generate_translations
mtdir=../../../..
wdir=$mtdir/worlds/$world
if [ ! -x $1 ]; then
echo mtt_updater not found at $1 pass the python script as first argument!
# Automatically run the mineclonia version that contains this script in a
# temporary world with the translation dumper mod and copy the resulting
# translation string files into the corresponding source mods.
#
# This script uses ``realpath`` to support being run from anywhere and to
# slightly beautify output. When run from its directory it should also work
# with ``realpath`` replaced by ``echo``. It also uses ``mktemp`` and expects
# symlinks to be supported by the file system of the temporary directory. We
# also assume that the directory name chosen by ``mktemp`` contains no space
# characters.
env >/dev/null 2>&1 which "$1" || (echo mod_translation_updater not found at $1, pass the python script as first argument!; false) || exit 1
# get directory of this script (with trailing slash)
mypath=$(realpath "$0")
mydir=${mypath%generate.sh}
# toplevel mineclonia directory
mcladir=$(realpath "${mydir}../..")
minetest=
parameters=
# search ``minetest`` or ``minetestserver`` executable
#
# First check whether we are inside the ``games`` directory of a minetest
# source build directory, alternatively check for minetest installed in
# ``PATH``. If the executable is ``minetest``, add ``--server`` parameter.
for dir in "${mydir}../../../../bin/" ""; do
for program in minetest minetestserver; do
command=$(command -v "${dir}${program}")
if [ -x "${command}" ]; then
minetest=$(realpath "${command}")
if [ "${program}" = "minetest" ]; then
parameters="${parameters} --server"
fi
break 2
fi
done
done
if [ -z "${minetest}" ]; then
echo minetest not found, either move mineclonia to the games directory of a run_in_place build of minetest, or make minetest available in PATH
exit 1
fi
if [ ! -x $mtdir/bin/minetest ]; then
echo This script needs to be run from the tools/generate_translation_strings directory within a run_in_place minetest
# prepare temporary directory
tmpdir=$(mktemp -d)
if [ ! -d ${tmpdir} ]; then
echo could not create temporary directory
exit 1
fi
if [ -d $mtdir/worlds/$world ]; then
echo Temp world $world already exists. Remove or rename it to run this script.
exit 1
fi
# create symlink for the special gameid used by the process to make sure that
# no other installation of mineclonia in the shared or user path is
# accidentally used instead of the one that contains this script
gameid=$(grep '^gameid *= *' "${mydir}world/world.mt" | cut -d = -f 2 | grep -o "[^ ][^ ]*")
ln -s "${mcladir}" "${tmpdir}/${gameid}"
mkdir -p $wdir/worldmods
cp -r mcla_generate_translation_strings $wdir/worldmods
echo "gameid = mineclonia" > $wdir/world.mt
echo -n Running minetest to extract complex translation strings...
$mtdir/bin/minetest --server --gameid mineclonia --worldname $world > /dev/null 2>&1
if [ -f $wdir/mcla_translate/mod_dirs.txt ]; then
echo done
else
# initialize world in temporary directory
cp -r "${mydir}world.conf" "${mydir}/world" "${tmpdir}"
echo Running ${minetest} to extract complex translation strings in ${tmpdir}...
MINETEST_GAME_PATH="${tmpdir}" "${minetest}" ${parameters} --config "${tmpdir}/world.conf" --world "${tmpdir}/world" --logfile "${tmpdir}/debug.txt" --quiet
# the following only works when ``tmpdir`` contains no space characters
# (which would be written to mod_dirs.txt, too)
if [ ! -f ${tmpdir}/world/mcla_translate/mod_dirs.txt ]; then
echo Running minetest did not produce any translation files.
echo The temporary world directory has been preserved so the situation can be investigated:
echo You can delete it by running rm -rf $wdir
echo The temporary directory has been preserved so the situation can be investigated:
echo You can delete it by running rm -rf \'${tmpdir}\'
exit 1
fi
cat $wdir/mcla_translate/mod_dirs.txt |while read f; do
cat ${tmpdir}/world/mcla_translate/mod_dirs.txt |while read f; do
mod=$(echo $f|cut -d " " -f1)
file=$(echo $f|cut -d " " -f2)
echo cp $wdir/mcla_translate/$file $mod
cp $tmpdir/world/mcla_translate/$file $mod
done
#$1 -r ../../mods
cat $wdir/mcla_translate/mod_dirs.txt |while read f; do
echo Running $1 on ${mcladir}/mods
"$1" -r "${mcladir}/mods"
cat ${tmpdir}/world/mcla_translate/mod_dirs.txt |while read f; do
mod=$(echo $f|cut -d " " -f1)
file=$(echo $f|cut -d " " -f2)
echo rm $mod/$file
rm $mod/$file
done
rm -rf $wdir
echo Mod translation strings have been extracted and updated. You will now want to create a new commit containing the new translation strings

View File

@ -0,0 +1 @@
# use empty user config while generating translation strings

View File

@ -0,0 +1,5 @@
mod_storage_backend = dummy
auth_backend = sqlite3
player_backend = dummy
backend = dummy
gameid = mineclonia_generate_translation_strings