forked from alexandrevicenzi/Flex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
translate.sh
executable file
·70 lines (62 loc) · 1.7 KB
/
translate.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
68
69
70
#!/usr/bin/env bash
function extract_pot() {
pybabel extract -s --no-wrap --project="Flex" --copyright-holder="Alexandre Vicenzi" --version="2.1.0" --mapping translations/babel.cfg --output translations/messages.pot ./
}
function new_translation() {
pybabel init --no-wrap --input-file translations/messages.pot --output-dir translations/ --locale $1 --domain messages
}
function update_translation() {
pybabel update --no-wrap --input-file translations/messages.pot --output-dir translations/ --domain messages
}
function compile_translations() {
pybabel compile -f --directory translations/ --domain messages
}
function can_run() {
if ! [ -x "$(command -v pybabel)" ]; then
echo "Missing translation tool. Please, install Flask-Babel to continue."
echo ""
echo " pip install Flask-Babel"
echo ""
exit 1
fi
}
function usage {
echo "Translate Flex theme tool"
echo ""
echo "Usage:"
echo ""
echo " new [language] create new translation."
echo " compile compile all PO files into MO files."
echo " update update all translations based on POT file."
echo " extract extract all messages from templates and create the POT file."
}
case "$1" in
"new")
can_run
if [ -z "$2" ]
then
echo "Error: missing translation code."
echo ""
usage
exit 1
else
new_translation $2
fi
;;
"compile")
can_run
compile_translations
;;
"update")
can_run
update_translation
;;
"extract")
can_run
extract_pot
;;
*)
usage
exit 1
;;
esac