-
Notifications
You must be signed in to change notification settings - Fork 85
/
translations.sh
executable file
·67 lines (56 loc) · 1.81 KB
/
translations.sh
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
PARAM1=$1
PARAM2=$2
# Function section
function serve_book() {
LANG=$1
# Rebuild english version, updating the `messages.pot` file where all chunks of texts
# to be translated are extracted.
MDBOOK_OUTPUT='{"xgettext": {"pot-file": "messages.pot"}}' \
mdbook build -d po
# Build available LANGUAGES. po file must exist for the languages listed
# in the LANGUAGE file. If it's not, you can add a language by running (xx replaced by the language code):
# msginit -i po/messages.pot -l xx -o po/xx.po
for po_lang in $(cat ./LANGUAGES)
do
echo merging and building "$po_lang"
msgmerge --update po/"$po_lang".po po/messages.pot
MDBOOK_BOOK__LANGUAGE="$po_lang" mdbook build -d book/"$po_lang"
done
# Serving the language, if any.
if [ -z "$LANG" ]
then
echo ""
echo "No input language, stop after build."
exit 0
fi
# Serve the input language, if available.
MDBOOK_BOOK__LANGUAGE="$LANG" mdbook serve -d book/"$LANG"
}
function build_new_language() {
LANG=$1
FILE=po/"$LANG".po
# Stop if no language parameter.
if [ -z "$LANG" ]
then
echo ""
echo "No input language, stop."
exit 0
fi
# Build a new LANGUAGE .po file if not exist .
if test -f "$FILE"; then
echo ""
echo "File $FILE already exists. Ensure you're initiating a new translation. Alternatively, use './transaction.sh $LANG' to serve an existing one."
else
msginit -i po/messages.pot -l "$LANG" -o po/"$LANG".po
fi
}
# Main section
if [ "$PARAM1" == "new" ]; then
# The first parameter is 'new', PARAM2 is set to $LANG.
LANG=$PARAM2
build_new_language "$LANG"
else
# The first parameter is not 'new', PARAM1 is set to $LANG.
LANG=$PARAM1
serve_book "$LANG"
fi