mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-25 01:11:00 +00:00
Merge pull request #358 from pierotofy/misc
Miscellaneous Fixes and Improvements
This commit is contained in:
commit
8be739a783
6 changed files with 40 additions and 27 deletions
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.3.2
|
||||
1.3.3
|
||||
|
|
32
app/app.py
32
app/app.py
|
@ -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] = sorted([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,13 @@ 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
|
||||
targets:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
description: Supported target language codes
|
||||
"""
|
||||
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
|
||||
|
@ -486,6 +485,9 @@ def create_app(args):
|
|||
results = []
|
||||
for idx, text in enumerate(q):
|
||||
translator = src_langs[idx].get_translation(tgt_lang)
|
||||
if translator is None:
|
||||
abort(400, description="%s (%s) is not available as a target language from %s (%s)" % (tgt_lang.name, tgt_lang.code, src_langs[idx].name, src_langs[idx].code))
|
||||
|
||||
if text_format == "html":
|
||||
translated_text = str(translate_html(translator, text))
|
||||
else:
|
||||
|
@ -501,12 +503,14 @@ def create_app(args):
|
|||
)
|
||||
else:
|
||||
return jsonify(
|
||||
{
|
||||
{
|
||||
"translatedText": results
|
||||
}
|
||||
}
|
||||
)
|
||||
else:
|
||||
translator = src_langs[0].get_translation(tgt_lang)
|
||||
if translator is None:
|
||||
abort(400, description="%s (%s) is not available as a target language from %s (%s)" % (tgt_lang.name, tgt_lang.code, src_langs[0].name, src_langs[0].code))
|
||||
|
||||
if text_format == "html":
|
||||
translated_text = str(translate_html(translator, q))
|
||||
|
@ -517,7 +521,7 @@ def create_app(args):
|
|||
return jsonify(
|
||||
{
|
||||
"translatedText": unescape(translated_text),
|
||||
"detectedLanguage": source_langs[0]
|
||||
"detectedLanguage": source_langs[0]
|
||||
}
|
||||
)
|
||||
else:
|
||||
|
@ -940,7 +944,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")
|
||||
|
|
|
@ -83,7 +83,10 @@ def improve_translation_formatting(source, translation, improve_punctuation=True
|
|||
|
||||
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]
|
||||
|
|
|
@ -61,14 +61,6 @@ h3.header {
|
|||
position: relative;
|
||||
}
|
||||
|
||||
@-moz-document url-prefix() {
|
||||
.language-select select {
|
||||
-moz-appearance: none;
|
||||
text-indent: -2px;
|
||||
margin-right: -8px;
|
||||
}
|
||||
}
|
||||
|
||||
.language-select:after {
|
||||
content: "";
|
||||
width: 0.5em;
|
||||
|
|
|
@ -141,8 +141,16 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
isHtml: function(){
|
||||
return htmlRegex.test(this.inputText);
|
||||
},
|
||||
canSendSuggestion() {
|
||||
canSendSuggestion: function(){
|
||||
return this.translatedText.trim() !== "" && this.translatedText !== this.savedTanslatedText;
|
||||
},
|
||||
targetLangs: function(){
|
||||
if (!this.sourceLang) return this.langs;
|
||||
else{
|
||||
var lang = this.langs.find(l => l.code === this.sourceLang);
|
||||
if (!lang) return this.langs;
|
||||
return lang.targets.map(t => this.langs.find(l => l.code === t));
|
||||
}
|
||||
}
|
||||
},
|
||||
filters: {
|
||||
|
@ -161,7 +169,13 @@ document.addEventListener('DOMContentLoaded', function(){
|
|||
}
|
||||
},
|
||||
swapLangs: function(e){
|
||||
this.closeSuggestTranslation(e)
|
||||
this.closeSuggestTranslation(e);
|
||||
|
||||
// Make sure that we can swap
|
||||
// by checking that the current target language
|
||||
// has source language as target
|
||||
var tgtLang = this.langs.find(l => l.code === this.targetLang);
|
||||
if (tgtLang.targets.indexOf(this.sourceLang) === -1) return; // Not supported
|
||||
|
||||
var t = this.sourceLang;
|
||||
this.sourceLang = this.targetLang;
|
||||
|
|
|
@ -156,7 +156,7 @@
|
|||
</a>
|
||||
<span>Translate into</span>
|
||||
<select class="browser-default" v-model="targetLang" ref="targetLangDropdown" @change="handleInput">
|
||||
<template v-for="option in langs">
|
||||
<template v-for="option in targetLangs">
|
||||
<option v-if="option.code !== 'auto'" :value="option.code">[[ option.name ]]</option>
|
||||
</template>
|
||||
</select>
|
||||
|
|
Loading…
Reference in a new issue