#!/bin/bash
# This file is part of GNU TALER.
# Copyright (C) 2014-2023 Taler Systems SA
#
# TALER is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 2.1, or (at your option) any later version.
#
# TALER 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with
# TALER; see the file COPYING. If not, see
#
# @author Florian Dold
# @author Benedikt Muller
# @author Sree Harsha Totakura
# @author Marcello Stanisci
# @author Christian Grothoff
#
#
# Error checking on
set -eu
# Call with target language as first argument.
function make_config()
{
XPWD=$(echo "$PWD" | sed -e "s/\//\\\\\\//g")
sed -e "s/%VERSION%/$VERSION/g" \
-e "s/%TITLE%/$TITLE/g" \
-e "s/%AUTHOR%/$AUTHOR/g" \
-e "s/%ORIGIN%/$XPWD/g" \
-e "s/%COPYRIGHT%/$COPYRIGHT/g" \
-e "s/%LANGUAGE%/$1/g" \
> "${BUILDDIR}/conf.py" <&2
exit 1
;;
esac
;;
t)
TITLE="$OPTARG"
;;
?)
echo "Unrecognized command line option" 1>&2
exit 1
;;
esac
done
if ! which sphinx-build > /dev/null
then
echo "Command 'sphinx-build' not found, but required. Please install sphinx." 1>&2
exit 1
fi
BUILDDIR=$(mktemp -d /tmp/taler-terms-XXXXXX)
if [ ! -f "${VERSION}.rst" ]
then
echo "Error: File '${VERSION}.rst' not found. Please check '-i' option." 1>&2
exit 1
fi
cp "${VERSION}.rst" "${BUILDDIR}/"
if [ -z ${TITLE+x} ]
then
TITLE=$(head -n1 "${VERSION}.rst")
echo "Title automatically set to '$TITLE'" 1>&2
fi
if [ -n "${ADD_LANGUAGE+x}" ]
then
if ! echo "${ADD_LANGUAGE}" | grep -e '^..$' > /dev/null
then
echo "Error: Invalid language '${ADD_LANGUAGE}'. Two characters (en, de, fr, ...) expected." 1>&2
exit 1
fi
echo "Adding language files for translations to '${ADD_LANGUAGE}'" 1>&2
make_config "${ADD_LANGUAGE}"
sphinx-build \
-b gettext \
-D language="${ADD_LANGUAGE}" \
-d "${BUILDDIR}/.doctrees" \
"${BUILDDIR}" \
"${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/" \
&> "${BUILDDIR}/add-language.log"
if [ -f "${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.po" ]
then
msgmerge --lang="${ADD_LANGUAGE}" \
--no-location \
-o "${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.mrg" \
"${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.po" \
"${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.pot"
mv "${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.mrg" \
"${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.po"
else
mv "${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.pot" \
"${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.po"
fi
rm -f "${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.pot"
echo "Done" 1>&2
exit 0
fi
for d in en $(ls -d locale/?? 2> /dev/null || true)
do
LANGUAGE=$(basename "$d")
echo "Generating files at '$OUTPUT' for ETag '$VERSION' and language '${LANGUAGE}' in '${BUILDDIR}':" 1>&2
make_config "$LANGUAGE"
mkdir -p "${OUTPUT}/${LANGUAGE}/"
LBUILD="sphinx-build -D language=${LANGUAGE} -d ${BUILDDIR}/.doctrees"
echo "$VERSION XML ($LANGUAGE)..." 1>&2
# shellcheck disable=SC2090
$LBUILD \
-b xml \
"${BUILDDIR}" \
"${BUILDDIR}/xml" \
&> "${BUILDDIR}/xml-sphinx.log"
mv "${BUILDDIR}/xml/${VERSION}.xml" "${OUTPUT}/${LANGUAGE}/${VERSION}.xml"
echo "$VERSION TXT ($LANGUAGE)..." 1>&2
# shellcheck disable=SC2090
$LBUILD \
-b text \
"${BUILDDIR}" \
"${BUILDDIR}/txt" \
&> "${BUILDDIR}/txt-sphinx.log"
mv "${BUILDDIR}/txt/${VERSION}.txt" "${OUTPUT}/${LANGUAGE}/${VERSION}.txt"
cp "${OUTPUT}/${LANGUAGE}/${VERSION}.txt" "${OUTPUT}/${LANGUAGE}/${VERSION}.md"
echo "$VERSION HTML ($LANGUAGE)..." 1>&2
# shellcheck disable=SC2090
$LBUILD \
-b html \
"${BUILDDIR}" \
"${BUILDDIR}/html" \
&> "${BUILDDIR}/html-sphinx.log"
htmlark \
-o "${OUTPUT}/${LANGUAGE}/${VERSION}.html" \
"${BUILDDIR}/html/${VERSION}.html"
echo "$VERSION EPUB ($LANGUAGE)..." 1>&2
# shellcheck disable=SC2090
$LBUILD \
-b epub \
"${BUILDDIR}" \
"${BUILDDIR}/epub" \
&> "${BUILDDIR}/epub-sphinx.log"
mv "${BUILDDIR}/epub/${VERSION}.epub" "${OUTPUT}/${LANGUAGE}/${VERSION}.epub"
echo "$VERSION PDF ($LANGUAGE)..." 1>&2
# shellcheck disable=SC2090
$LBUILD \
-b latex \
-D latex_paper_size="${PAPER}" \
"${BUILDDIR}" \
"${BUILDDIR}/pdf" \
&> "${BUILDDIR}/pdf-sphinx.log"
make \
-C "${BUILDDIR}/pdf" \
all-pdf \
&> "${BUILDDIR}/pdf-latex.log"
mv "${BUILDDIR}/pdf/${VERSION}.pdf" "${OUTPUT}/${LANGUAGE}/${VERSION}.pdf"
done
echo "Done" 1>&2
exit 0