1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-11-05 07:20:13 +01:00

Merge pull request #145 from pierotofy/htmlfix

Fix HTML Translation Formatting, Auto detect HTML in UI
This commit is contained in:
Piero Toffanin 2021-09-24 11:32:28 -04:00 committed by GitHub
commit f9245c56e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -425,7 +425,7 @@ def create_app(args):
translator = src_langs[idx].get_translation(tgt_lang)
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:
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)
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:
translated_text = translator.translate(transliterate(q, target_lang=source_langs[0]))
return jsonify(

View File

@ -241,7 +241,7 @@
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
// API host/endpoint
var BaseUrl = window.location.protocol + "//" + window.location.host;
var htmlRegex = /<(.*)>.*?|<(.*)\/>/;
document.addEventListener('DOMContentLoaded', function(){
var sidenavElems = document.querySelectorAll('.sidenav');
var sidenavInstances = M.Sidenav.init(sidenavElems);
@ -366,12 +366,17 @@
' body: JSON.stringify({',
' q: "' + this.$options.filters.escape(this.inputText) + '",',
' 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" }',
'});',
'',
'console.log(await res.json());'].join("\n");
},
isHtml: function(){
return htmlRegex.test(this.inputText);
}
},
filters: {
@ -425,6 +430,7 @@
data.append("q", self.inputText);
data.append("source", self.sourceLang);
data.append("target", self.targetLang);
data.append("format", self.isHtml ? "html" : "text");
data.append("api_key", localStorage.getItem("api_key") || "");
request.open('POST', BaseUrl + '/translate', true);

View File

@ -3,7 +3,7 @@
from setuptools import setup, find_packages
setup(
version='1.2.4',
version='1.2.5',
name='libretranslate',
license='GNU Affero General Public License v3.0',
description='Free and Open Source Machine Translation API. Self-hosted, no limits, no ties to proprietary services.',