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
45649c33
Unverified
Commit
45649c33
authored
3 years ago
by
Piero Toffanin
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #219 from ZenulAbidin/detect_fix
Fix language detection error
parents
bcf051b7
e23b96f1
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
-1
2 additions, 1 deletion
app/app.py
app/language.py
+7
-3
7 additions, 3 deletions
app/language.py
with
9 additions
and
4 deletions
app/app.py
+
2
−
1
View file @
45649c33
...
...
@@ -102,7 +102,7 @@ def create_app(args):
boot
(
args
.
load_only
)
from
app.language
import
languages
from
app.language
import
load_
languages
app
=
Flask
(
__name__
)
...
...
@@ -111,6 +111,7 @@ def create_app(args):
if
not
args
.
disable_files_translation
:
remove_translated_files
.
setup
(
get_upload_dir
())
languages
=
load_languages
()
# Map userdefined frontend languages to argos language object.
if
args
.
frontend_language_source
==
"
auto
"
:
...
...
This diff is collapsed.
Click to expand it.
app/language.py
+
7
−
3
View file @
45649c33
...
...
@@ -4,11 +4,11 @@ from argostranslate import translate
from
polyglot.detect.base
import
Detector
,
UnknownLanguage
from
polyglot.transliteration.base
import
Transliterator
languages
=
translate
.
load_installed_languages
()
__lang_codes
=
[
l
.
code
for
l
in
languages
]
def
load_languages
():
languages
=
translate
.
load_installed_languages
()
return
languages
def
detect_languages
(
text
):
# detect batch processing
...
...
@@ -32,6 +32,10 @@ def detect_languages(text):
# total read bytes of the provided text
text_length_total
=
sum
(
c
.
text_length
for
c
in
candidates
)
# Load language codes
languages
=
load_languages
()
__lang_codes
=
[
l
.
code
for
l
in
languages
]
# only use candidates that are supported by argostranslate
candidate_langs
=
list
(
filter
(
lambda
l
:
l
.
text_length
!=
0
and
l
.
code
in
__lang_codes
,
candidates
)
...
...
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