-
Notifications
You must be signed in to change notification settings - Fork 44
/
manage-i18n.sh
executable file
·72 lines (64 loc) · 2.49 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
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
#!/bin/bash
# This file is part of the Indico plugins.
# Copyright (C) 2002 - 2024 CERN
#
# The Indico plugins are free software; you can redistribute
# them and/or modify them under the terms of the MIT License;
# see the LICENSE file for more details.
USAGE="$0 [init <locale>|extract|update <locale>|compile <locale>] [plugin...]"
if [[ $# -eq 0 || "$1" == '-h' || "$1" == '--help' ]]; then
echo "$USAGE"
exit 0
fi
ACTION="$1"
LOCALE="$2"
PLUGINS=$(find . -name pyproject.toml -exec sh -c 'basename $(dirname $0)' {} \;)
if [[ "$ACTION" == "extract" ]]; then
PLUGINSINPARAMS=${@:2}
else
PLUGINSINPARAMS=${@:3}
fi
if [[ ! -z $PLUGINSINPARAMS ]]; then
PLUGINS=$PLUGINSINPARAMS
fi
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 $PLUGINS; do
[[ "$plugin" == "_meta" ]] && continue
[[ ! -d "$plugin" ]] && echo "plugin $plugin not found" && exit 1
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
num_strings=$(grep msgid "${TRANSLATIONS_DIR}/messages.pot" | wc -l)
if (( $num_strings == 1 )); then
echo "deleting empty dict ${TRANSLATIONS_DIR}/messages.pot"
rm "${TRANSLATIONS_DIR}/messages.pot"
fi
pybabel extract -o "${TRANSLATIONS_DIR}/messages-js.pot" "indico_${plugin}" -k '$t.gettext' -k '$t.ngettext:1,2' -F ../babel-js.cfg
num_strings=$(grep msgid "${TRANSLATIONS_DIR}/messages-js.pot" | wc -l)
if (( $num_strings == 1 )); then
echo "deleting empty js dict ${TRANSLATIONS_DIR}/messages-js.pot"
rm "${TRANSLATIONS_DIR}/messages-js.pot"
fi
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 -f -d "./indico_${plugin}/translations/" -l "$LOCALE"
fi
popd >/dev/null
done