Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
LibreTranslate
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Riße, Matthias
LibreTranslate
Commits
b73e146b
Commit
b73e146b
authored
3 years ago
by
Piero Toffanin
Browse files
Options
Downloads
Patches
Plain Diff
Fix HTML translation formatting, automatically detect HTML in translation UI
parent
d207ed3b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/app.py
+2
-2
2 additions, 2 deletions
app/app.py
app/templates/index.html
+8
-2
8 additions, 2 deletions
app/templates/index.html
with
10 additions
and
4 deletions
app/app.py
+
2
−
2
View file @
b73e146b
...
...
@@ -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
,
t
ransliterate
(
text
,
target_lang
=
source_langs
[
idx
])
))
translated_text
=
str
(
translate_html
(
translator
,
t
ext
))
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
(
...
...
This diff is collapsed.
Click to expand it.
app/templates/index.html
+
8
−
2
View file @
b73e146b
...
...
@@ -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
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment