mirror of
https://github.com/veops/cmdb.git
synced 2025-08-08 12:37:14 +08:00
feat(api): i18n
feat(api): i18n
This commit is contained in:
@@ -5,9 +5,7 @@ from glob import glob
|
||||
from subprocess import call
|
||||
|
||||
import click
|
||||
from flask import current_app
|
||||
from flask.cli import with_appcontext
|
||||
from werkzeug.exceptions import MethodNotAllowed, NotFound
|
||||
|
||||
from api.extensions import db
|
||||
|
||||
@@ -90,3 +88,40 @@ def db_setup():
|
||||
"""create tables
|
||||
"""
|
||||
db.create_all()
|
||||
|
||||
|
||||
@click.group()
|
||||
def translate():
|
||||
"""Translation and localization commands."""
|
||||
|
||||
|
||||
@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 api/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 api/translations'):
|
||||
raise RuntimeError('update command failed')
|
||||
os.remove('messages.pot')
|
||||
|
||||
|
||||
@translate.command()
|
||||
def compile():
|
||||
"""Compile all languages."""
|
||||
|
||||
if os.system('pybabel compile -d api/translations'):
|
||||
raise RuntimeError('compile command failed')
|
||||
|
Reference in New Issue
Block a user