Permalink
Cannot retrieve contributors at this time
executable file
70 lines (62 sloc)
1.7 KB
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Flex/translate.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |