StarfallBot/babel.fish

134 lines
2.9 KiB
Fish
Executable File

#!/bin/fish
function display_help
set_color brgreen
echo -n "1) t) "
set_color normal
echo " Extract translations into messages.pot file"
echo " and merge into existing languages"
set_color brgreen
echo -n "2) l) "
set_color normal
echo " Create translation folders for new language"
set_color brgreen
echo -n "3) c) "
set_color normal
echo " Compile *.po files for display"
set_color red
echo -n "4) e) q) "
set_color normal
echo "Exit program"
echo
end
function compile_pot
set_color brgreen
echo "Compiling POT file..."
set_color normal
set -l tl_version "$(cat VERSION.md)"
command pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot --add-location full \
--project Starfall --version "$tl_version" \
--copyright-holder "Flare Starfall" --msgid-bugs-address "flare@theflare.at" .
if test -d translations
set_color brgreen
echo "Merging into existing languages..."
set_color normal
command pybabel update -i messages.pot -d translations
end
set_color brgreen
echo -n "Command complete "
set_color normal
echo "- returning to menu"
echo
end
function new_lang
read -p "set_color green; echo -n \"Please enter language >>> \"; set_color normal" -l lang
if test -d "translations/$lang"
set_color brred
echo -n "ERROR "
set_color normal
echo "- Language already exists"
echo
else
set_color brgreen
echo "Initializing language $lang..."
set_color normal
command pybabel init -i messages.pot -d translations -l "$lang"
set_color brgreen
echo -n "Command complete "
set_color normal
echo "- returning to menu"
echo
end
end
function compile_po
set_color brgreen
echo "Compiling PO files..."
set_color normal
command pybabel compile -d translations
set_color brgreen
echo -n "Command complete "
set_color normal
echo "- returning to menu"
echo
end
if test -f .venv/bin/activate.fish
source .venv/bin/activate.fish
end
if test -f .venv/Scripts/activate.fish
source .venv/Scripts/activate.fish
end
set_color brgreen
echo -n "pybabel version >>> "
set_color normal
command pybabel --version
if test $status -ne 0
set_color brred
echo "Could not read pybabel - Please check venv"
set_color normal
return 1
end
while true
display_help
read -p "set_color green; echo -n \"Please enter operation >>> \"; set_color normal" -n 1 -l confirm
or return 1
switch $confirm
case 1 t
compile_pot
case 2 l
new_lang
case 3 c
compile_po
case 4 e q
return 0
case '' '*'
echo "Invalid input"
continue
end
end