flex/translate.sh
2016-09-13 21:45:14 -03:00

70 lines
1.6 KiB
Bash
Executable file

#!/usr/bin/env bash
function extract_pot() {
pybabel extract --mapping translations/babel.cfg --output translations/messages.pot ./
}
function new_translation() {
pybabel init --input-file translations/messages.pot --output-dir translations/ --locale $1 --domain messages
}
function update_translation() {
pybabel update --input-file translations/messages.pot --output-dir translations/ --domain messages
}
function compile_translations() {
pybabel compile --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