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
73ebb961
Unverified
Commit
73ebb961
authored
3 years ago
by
Sébastien Thuret
Browse files
Options
Downloads
Patches
Plain Diff
fix
parent
4f0d19db
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/app.py
+13
-10
13 additions, 10 deletions
app/app.py
app/static/js/app.js
+5
-4
5 additions, 4 deletions
app/static/js/app.js
app/templates/index.html
+5
-2
5 additions, 2 deletions
app/templates/index.html
with
23 additions
and
16 deletions
app/app.py
+
13
−
10
View file @
73ebb961
import
io
import
os
import
tempfile
import
uuid
...
...
@@ -6,7 +7,7 @@ from functools import wraps
import
argostranslatefiles
import
pkg_resources
from
argostranslatefiles
import
get_supported_formats
from
flask
import
Flask
,
abort
,
jsonify
,
render_template
,
request
,
url_for
,
send_from_directory
from
flask
import
Flask
,
abort
,
jsonify
,
render_template
,
request
,
url_for
,
send_from_directory
,
send_file
from
flask_swagger
import
swagger
from
flask_swagger_ui
import
get_swaggerui_blueprint
from
translatehtml
import
translate_html
...
...
@@ -548,14 +549,8 @@ def create_app(args):
type: string
description: Error message
"""
if
request
.
is_json
:
json
=
get_json_dict
(
request
)
source_lang
=
json
.
get
(
"
source
"
)
target_lang
=
json
.
get
(
"
target
"
)
else
:
source_lang
=
request
.
values
.
get
(
"
source
"
)
target_lang
=
request
.
values
.
get
(
"
target
"
)
source_lang
=
request
.
form
.
get
(
"
source
"
)
target_lang
=
request
.
form
.
get
(
"
target
"
)
file
=
request
.
files
[
'
file
'
]
if
not
file
:
...
...
@@ -606,8 +601,16 @@ def create_app(args):
Download a translated file
"""
filename
.
split
(
'
.
'
).
pop
(
0
)
filepath
=
os
.
path
.
join
(
tempfile
.
gettempdir
(),
filename
)
return_data
=
io
.
BytesIO
()
with
open
(
filepath
,
'
rb
'
)
as
fo
:
return_data
.
write
(
fo
.
read
())
return_data
.
seek
(
0
)
os
.
remove
(
filepath
)
return
send_f
rom_directory
(
directory
=
tempfile
.
gettempdir
(),
filename
=
filename
)
return
send_f
ile
(
return_data
,
attachment_
filename
=
filename
)
@app.route
(
"
/detect
"
,
methods
=
[
"
POST
"
])
@access_check
...
...
This diff is collapsed.
Click to expand it.
app/static/js/app.js
+
5
−
4
View file @
73ebb961
...
...
@@ -328,17 +328,18 @@ document.addEventListener('DOMContentLoaded', function(){
let
formdata
=
new
FormData
();
formdata
.
append
(
"
file
"
,
this
.
inputFile
);
translateFileRequest
.
send
(
formdata
);
formdata
.
append
(
"
source
"
,
this
.
sourceLang
);
formdata
.
append
(
"
target
"
,
this
.
targetLang
);
this
.
loadingFileTranslation
=
true
translateFileRequest
.
on
readystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
&&
xhr
.
status
==
200
)
{
translateFileRequest
.
on
load
=
()
=>
{
if
(
translateFileRequest
.
readyState
==
=
4
&&
translateFileRequest
.
status
==
=
200
)
{
this
.
loadingFileTranslation
=
false
}
}
translateFileRequest
.
send
(
formdata
);
}
}
});
...
...
This diff is collapsed.
Click to expand it.
app/templates/index.html
+
5
−
2
View file @
73ebb961
...
...
@@ -196,14 +196,17 @@
<p>
[[ inputFile.name ]]
</p>
</div>
<div
class=
"col s2"
>
<button
@
click=
"removeFile"
class=
"btn-flat"
>
<button
v-if=
"loadingFileTranslation !== true"
@
click=
"removeFile"
class=
"btn-flat"
>
<i
class=
"material-icons"
>
close
</i>
</button>
</div>
</div>
</div>
</div>
<button
@
click=
"translateFile"
class=
"btn"
>
Translate
</button>
<button
@
click=
"translateFile"
v-if=
"loadingFileTranslation === false"
class=
"btn"
>
Translate
</button>
<div
class=
"progress"
v-if=
"loadingFileTranslation"
>
<div
class=
"indeterminate"
></div>
</div>
</div>
</div>
</div>
...
...
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