mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-12-24 10:06:43 +02:00
Fix HTML translation formatting, automatically detect HTML in translation UI
This commit is contained in:
parent
d207ed3b88
commit
b73e146baf
@ -425,7 +425,7 @@ def create_app(args):
|
|||||||
translator = src_langs[idx].get_translation(tgt_lang)
|
translator = src_langs[idx].get_translation(tgt_lang)
|
||||||
|
|
||||||
if text_format == "html":
|
if text_format == "html":
|
||||||
translated_text = str(translate_html(translator, transliterate(text, target_lang=source_langs[idx])))
|
translated_text = str(translate_html(translator, text))
|
||||||
else:
|
else:
|
||||||
translated_text = translator.translate(transliterate(text, target_lang=source_langs[idx]))
|
translated_text = translator.translate(transliterate(text, target_lang=source_langs[idx]))
|
||||||
|
|
||||||
@ -439,7 +439,7 @@ def create_app(args):
|
|||||||
translator = src_langs[0].get_translation(tgt_lang)
|
translator = src_langs[0].get_translation(tgt_lang)
|
||||||
|
|
||||||
if text_format == "html":
|
if text_format == "html":
|
||||||
translated_text = str(translate_html(translator, transliterate(q, target_lang=source_langs[0])))
|
translated_text = str(translate_html(translator, q))
|
||||||
else:
|
else:
|
||||||
translated_text = translator.translate(transliterate(q, target_lang=source_langs[0]))
|
translated_text = translator.translate(transliterate(q, target_lang=source_langs[0]))
|
||||||
return jsonify(
|
return jsonify(
|
||||||
|
@ -241,7 +241,7 @@
|
|||||||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
|
||||||
// API host/endpoint
|
// API host/endpoint
|
||||||
var BaseUrl = window.location.protocol + "//" + window.location.host;
|
var BaseUrl = window.location.protocol + "//" + window.location.host;
|
||||||
|
var htmlRegex = /<(.*)>.*?|<(.*)\/>/;
|
||||||
document.addEventListener('DOMContentLoaded', function(){
|
document.addEventListener('DOMContentLoaded', function(){
|
||||||
var sidenavElems = document.querySelectorAll('.sidenav');
|
var sidenavElems = document.querySelectorAll('.sidenav');
|
||||||
var sidenavInstances = M.Sidenav.init(sidenavElems);
|
var sidenavInstances = M.Sidenav.init(sidenavElems);
|
||||||
@ -366,12 +366,17 @@
|
|||||||
' body: JSON.stringify({',
|
' body: JSON.stringify({',
|
||||||
' q: "' + this.$options.filters.escape(this.inputText) + '",',
|
' q: "' + this.$options.filters.escape(this.inputText) + '",',
|
||||||
' source: "' + this.$options.filters.escape(this.sourceLang) + '",',
|
' source: "' + this.$options.filters.escape(this.sourceLang) + '",',
|
||||||
' target: "' + this.$options.filters.escape(this.targetLang) + '"',
|
' target: "' + this.$options.filters.escape(this.targetLang) + '",',
|
||||||
|
' format: "' + (this.isHtml ? "html" : "text") + '"',
|
||||||
' }),',
|
' }),',
|
||||||
' headers: { "Content-Type": "application/json" }',
|
' headers: { "Content-Type": "application/json" }',
|
||||||
'});',
|
'});',
|
||||||
'',
|
'',
|
||||||
'console.log(await res.json());'].join("\n");
|
'console.log(await res.json());'].join("\n");
|
||||||
|
},
|
||||||
|
|
||||||
|
isHtml: function(){
|
||||||
|
return htmlRegex.test(this.inputText);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
filters: {
|
filters: {
|
||||||
@ -425,6 +430,7 @@
|
|||||||
data.append("q", self.inputText);
|
data.append("q", self.inputText);
|
||||||
data.append("source", self.sourceLang);
|
data.append("source", self.sourceLang);
|
||||||
data.append("target", self.targetLang);
|
data.append("target", self.targetLang);
|
||||||
|
data.append("format", self.isHtml ? "html" : "text");
|
||||||
data.append("api_key", localStorage.getItem("api_key") || "");
|
data.append("api_key", localStorage.getItem("api_key") || "");
|
||||||
|
|
||||||
request.open('POST', BaseUrl + '/translate', true);
|
request.open('POST', BaseUrl + '/translate', true);
|
||||||
|
Loading…
Reference in New Issue
Block a user