mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-21 23:41:01 +00:00
Extend /languages to include targets
This commit is contained in:
parent
0478d4ee2c
commit
e79089b5c1
3 changed files with 10 additions and 13 deletions
16
app/app.py
16
app/app.py
|
@ -112,6 +112,9 @@ def create_app(args):
|
||||||
if not args.disable_files_translation:
|
if not args.disable_files_translation:
|
||||||
remove_translated_files.setup(get_upload_dir())
|
remove_translated_files.setup(get_upload_dir())
|
||||||
languages = load_languages()
|
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.
|
# Map userdefined frontend languages to argos language object.
|
||||||
if args.frontend_language_source == "auto":
|
if args.frontend_language_source == "auto":
|
||||||
|
@ -269,17 +272,8 @@ def create_app(args):
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
description: Human-readable language name (in English)
|
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
|
# Add cors
|
||||||
@app.after_request
|
@app.after_request
|
||||||
|
@ -940,7 +934,7 @@ def create_app(args):
|
||||||
return jsonify({"success": True})
|
return jsonify({"success": True})
|
||||||
|
|
||||||
swag = swagger(app)
|
swag = swagger(app)
|
||||||
swag["info"]["version"] = "1.3.0"
|
swag["info"]["version"] = "1.3.1"
|
||||||
swag["info"]["title"] = "LibreTranslate"
|
swag["info"]["title"] = "LibreTranslate"
|
||||||
|
|
||||||
@app.route("/spec")
|
@app.route("/spec")
|
||||||
|
|
|
@ -81,9 +81,12 @@ def detect_languages(text):
|
||||||
def improve_translation_formatting(source, translation, improve_punctuation=True):
|
def improve_translation_formatting(source, translation, improve_punctuation=True):
|
||||||
source = source.strip()
|
source = source.strip()
|
||||||
|
|
||||||
if not len(source) or not len(translation):
|
if not len(source):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
if not len(translation):
|
||||||
|
return source
|
||||||
|
|
||||||
if improve_punctuation:
|
if improve_punctuation:
|
||||||
source_last_char = source[len(source) - 1]
|
source_last_char = source[len(source) - 1]
|
||||||
translation_last_char = translation[len(translation) - 1]
|
translation_last_char = translation[len(translation) - 1]
|
||||||
|
|
|
@ -141,7 +141,7 @@ document.addEventListener('DOMContentLoaded', function(){
|
||||||
isHtml: function(){
|
isHtml: function(){
|
||||||
return htmlRegex.test(this.inputText);
|
return htmlRegex.test(this.inputText);
|
||||||
},
|
},
|
||||||
canSendSuggestion() {
|
canSendSuggestion: function(){
|
||||||
return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText;
|
return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue