Extend /languages to include targets

This commit is contained in:
Piero Toffanin 2022-12-09 16:36:12 -05:00
parent 0478d4ee2c
commit e79089b5c1
3 changed files with 10 additions and 13 deletions

View file

@ -112,6 +112,9 @@ def create_app(args):
if not args.disable_files_translation:
remove_translated_files.setup(get_upload_dir())
languages = load_languages()
language_pairs = {}
for lang in languages:
language_pairs[lang.code] = [l.to_lang.code for l in lang.translations_from]
# Map userdefined frontend languages to argos language object.
if args.frontend_language_source == "auto":
@ -269,17 +272,8 @@ def create_app(args):
name:
type: string
description: Human-readable language name (in English)
429:
description: Slow down
schema:
id: error-slow-down
type: object
properties:
error:
type: string
description: Reason for slow down
"""
return jsonify([{"code": l.code, "name": l.name} for l in languages])
return jsonify([{"code": l.code, "name": l.name, "targets": [language_pairs.get(l.code, [])]} for l in languages])
# Add cors
@app.after_request
@ -940,7 +934,7 @@ def create_app(args):
return jsonify({"success": True})
swag = swagger(app)
swag["info"]["version"] = "1.3.0"
swag["info"]["version"] = "1.3.1"
swag["info"]["title"] = "LibreTranslate"
@app.route("/spec")

View file

@ -81,9 +81,12 @@ def detect_languages(text):
def improve_translation_formatting(source, translation, improve_punctuation=True):
source = source.strip()
if not len(source) or not len(translation):
if not len(source):
return ""
if not len(translation):
return source
if improve_punctuation:
source_last_char = source[len(source) - 1]
translation_last_char = translation[len(translation) - 1]

View file

@ -141,7 +141,7 @@ document.addEventListener('DOMContentLoaded', function(){
isHtml: function(){
return htmlRegex.test(this.inputText);
},
canSendSuggestion() {
canSendSuggestion: function(){
return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText;
}
},