2023-08-29 03:01:06 -07:00
|
|
|
# if commands in this file are not working (e.g. 'flask translate') make sure you set the FLASK_APP environment variable.
|
|
|
|
# e.g. export FLASK_APP=pyfedi.py
|
|
|
|
|
|
|
|
|
|
|
|
from app import db
|
2023-07-27 21:22:12 -07:00
|
|
|
import click
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
def register(app):
|
|
|
|
@app.cli.group()
|
|
|
|
def translate():
|
|
|
|
"""Translation and localization commands."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@translate.command()
|
|
|
|
@click.argument('lang')
|
|
|
|
def init(lang):
|
|
|
|
"""Initialize a new language."""
|
|
|
|
if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'):
|
|
|
|
raise RuntimeError('extract command failed')
|
|
|
|
if os.system(
|
|
|
|
'pybabel init -i messages.pot -d app/translations -l ' + lang):
|
|
|
|
raise RuntimeError('init command failed')
|
|
|
|
os.remove('messages.pot')
|
|
|
|
|
|
|
|
@translate.command()
|
|
|
|
def update():
|
|
|
|
"""Update all languages."""
|
|
|
|
if os.system('pybabel extract -F babel.cfg -k _l -o messages.pot .'):
|
|
|
|
raise RuntimeError('extract command failed')
|
|
|
|
if os.system('pybabel update -i messages.pot -d app/translations'):
|
|
|
|
raise RuntimeError('update command failed')
|
|
|
|
os.remove('messages.pot')
|
|
|
|
|
|
|
|
@translate.command()
|
|
|
|
def compile():
|
|
|
|
"""Compile all languages."""
|
|
|
|
if os.system('pybabel compile -d app/translations'):
|
|
|
|
raise RuntimeError('compile command failed')
|
2023-08-29 03:01:06 -07:00
|
|
|
|
|
|
|
@app.cli.command("init-db")
|
|
|
|
def init_db():
|
|
|
|
with app.app_context():
|
|
|
|
db.drop_all()
|
|
|
|
db.configure_mappers()
|
|
|
|
db.create_all()
|
|
|
|
db.session.commit()
|
|
|
|
print("Done")
|