Translation scripts

This commit is contained in:
Piero Toffanin 2023-01-04 12:15:18 -05:00
parent bd9a153773
commit 05900ff556
8 changed files with 71 additions and 5 deletions

View file

@ -15,6 +15,7 @@ from flask_swagger_ui import get_swaggerui_blueprint
from translatehtml import translate_html
from werkzeug.utils import secure_filename
from werkzeug.exceptions import HTTPException
from flask_babel import Babel, gettext as _
from libretranslate import flood, remove_translated_files, security
from libretranslate.language import detect_languages, improve_translation_formatting
@ -53,7 +54,7 @@ def get_req_api_key():
def get_json_dict(request):
d = request.get_json()
if not isinstance(d, dict):
abort(400, description="Invalid JSON format")
abort(400, description=_("Invalid JSON format"))
return d
@ -121,7 +122,7 @@ def create_app(args):
# Map userdefined frontend languages to argos language object.
if args.frontend_language_source == "auto":
frontend_argos_language_source = type(
"obj", (object,), {"code": "auto", "name": "Auto Detect"}
"obj", (object,), {"code": "auto", "name": _("Auto Detect")}
)
else:
frontend_argos_language_source = next(
@ -294,6 +295,14 @@ def create_app(args):
return render_template("javascript-licenses.html")
@bp.route("/static/js/app.js")
@limiter.exempt
def appjs():
if args.disable_web_ui:
abort(404)
return render_template("app.js.template")
@bp.get("/languages")
@limiter.exempt
def langs():
@ -1002,12 +1011,18 @@ def create_app(args):
swag["info"]["version"] = get_version()
swag["info"]["title"] = "LibreTranslate"
@app.route(API_URL)
@limiter.exempt
def spec():
return jsonify(swag)
babel = Babel(app)
@babel.localeselector
def get_locale():
# TODO: populate from available locales
return request.accept_languages.best_match(['en', 'it'])
# Call factory function to create our blueprint
swaggerui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
if args.url_prefix:

View file

@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', function(){
detectedLangText: "",
copyTextLabel: "Copy text",
copyTextLabel: {{ _("Copy text") }},
suggestions: false,
isSuggesting: false,

View file

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LibreTranslate - Free and Open Source Machine Translation API</title>
<title>LibreTranslate - {{ _("Free and Open Source Machine Translation API") }}</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<meta name="description" content="Free and Open Source Machine Translation API. 100% self-hosted, offline capable and easy to setup. Run your own API server in just a few minutes.">
<meta name="keywords" content="translation,api">

View file

@ -0,0 +1 @@
**/*.mo