forked from indico/indico-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage-i18n.sh
executable file
·43 lines (37 loc) · 1.44 KB
/
manage-i18n.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
#!/bin/sh
USAGE="$0 [init <locale>|extract|update <locale>|compile <locale>]"
if [[ $# -eq 0 || "$1" == '-h' || "$1" == '--help' ]]; then
echo "$USAGE"
exit 0
fi
ACTION="$1"
LOCALE="$2"
function require_locale {
if [[ -z "$LOCALE" ]]; then
echo "$USAGE"
exit 1
fi
}
if [[ ! "init extract update compile" =~ $ACTION ]]; then
echo "$USAGE"
exit 1
fi
for plugin in $(find . -name setup.py -exec sh -c 'basename $(dirname $0)' {} \;); do
pushd "${plugin}" >/dev/null
if [[ "$ACTION" == "init" ]]; then
require_locale
pybabel init -l "$LOCALE" -i "./indico_${plugin}/translations/messages.pot" -d "./indico_${plugin}/translations/"
elif [[ "$ACTION" == "extract" ]]; then
TRANSLATIONS_DIR="./indico_${plugin}/translations"
[[ ! -d "$TRANSLATIONS_DIR" ]] && mkdir "$TRANSLATIONS_DIR"
pybabel extract -o "${TRANSLATIONS_DIR}/messages.pot" "indico_${plugin}" -F ../babel.cfg
pybabel extract -o "${TRANSLATIONS_DIR}/messages-js.pot" "indico_${plugin}" -k 'gettext' -k 'ngettext:1,2' -k '$T' -F ../babel-js.cfg
elif [[ "$ACTION" == "update" ]]; then
require_locale
pybabel update -i "./indico_${plugin}/translations/messages.pot" -l "$LOCALE" -d "./indico_${plugin}/translations"
elif [[ "$ACTION" == "compile" ]]; then
require_locale
pybabel compile -d "./indico_${plugin}/translations/" -l "$LOCALE"
fi
popd >/dev/null
done