1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#!/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 <http://www.gnu.org/licenses/>
#
# @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" <<EOF
import sys
import os
sys.path.append(os.path.abspath('_exts'))
needs_sphinx = '1.8.5'
extensions = [
'sphinx.ext.todo',
'sphinx.ext.imgmath',
]
templates_path = ['_templates']
source_suffix = {
'.rst': 'restructuredtext',
}
master_doc = '%VERSION%'
project = u'%VERSION%'
copyright = u'%COPYRIGHT%'
version = '%VERSION%'
release = '%VERSION%'
language = "%LANGUAGE%"
exclude_patterns = ['_build', '_exts', 'cf', 'prebuilt']
locale_dirs = ['%ORIGIN%/locale/']
gettext_compact = False
pygments_style = 'sphinx'
html_theme = 'epub'
rst_epilog = ""
html_show_sphinx = False
html_theme_options = {
"relbar1": "false",
"footer": "false",
}
html_title = "%TITLE%"
html_short_title = "%TITLE%"
html_use_index = True
html_show_sphinx = False
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
latex_documents = [
('%VERSION%', '%VERSION%.tex',
'%TITLE%', '%AUTHOR%', 'manual'),
]
epub_basename = "%VERSION%"
epub_title = "%TITLE%"
EOF
}
# defaults
AUTHOR="GNU Taler team"
VERSION="tos-v0"
OUTPUT="%termsdir%"
PAPER="a4"
COPYRIGHT="2014-2023 Taler Systems SA (GPLv3+ or GFDL 1.3+)"
# Parse command-line options
while getopts ':a:C:hi:l:o:p:t:' OPTION; do
case "$OPTION" in
a)
AUTHOR="$OPTARG"
;;
C)
COPYRIGHT="$OPTARG"
;;
h)
echo 'Supported options:'
echo ' -a AUTHOR -- set author header' "(default: $AUTHOR)"
echo ' -C COPYRIGHT -- set copyright header' "(default: $COPYRIGHT)"
echo ' -h -- print this help'
echo ' -i INPUT -- input file to convert' "(default: $VERSION)"
echo ' -l LANGUAGE -- target language to add'
echo ' -o OUTPUT -- output directory' "(default: $OUTPUT)"
echo ' -p PAPER -- paper format' "(default: $PAPER)"
echo ' -t TITLE -- title of the document to generate'
exit 0
;;
l)
ADD_LANGUAGE="$OPTARG"
;;
i)
VERSION="$OPTARG"
;;
o)
OUTPUT="$OPTARG"
;;
p)
PAPER="$OPTARG"
case "$PAPER" in
a4|letter)
;;
*)
echo "Error: Paper format '$PAPER' invalid (use 'a4' or 'letter')"
exit 1
;;
esac
;;
t)
TITLE="$OPTARG"
;;
?)
exit_fail "Unrecognized command line option"
;;
esac
done
if ! which sphinx-build > /dev/null
then
echo "Command 'sphinx-build' not found, but required. Please install sphinx."
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."
exit 1
fi
cp "${VERSION}.rst" "${BUILDDIR}/"
if [ -z ${TITLE+x} ]
then
TITLE=$(head -n1 "${VERSION}.rst")
echo "Title automatically set to '$TITLE'"
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."
exit 1
fi
echo "Adding language files for translations to '${ADD_LANGUAGE}'"
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 "${PWD}/locale/${ADD_LANGUAGE}/LC_MESSAGES/${VERSION}.pot"
echo "Done"
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}':"
make_config "$LANGUAGE"
mkdir -p "${OUTPUT}/${LANGUAGE}/"
LBUILD="sphinx-build -D language=${LANGUAGE} -d ${BUILDDIR}/.doctrees"
echo "$VERSION XML ($LANGUAGE)..."
# 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)..."
# 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)..."
# 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)..."
# 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)..."
# 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"
exit 0
|