mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2025-05-04 12:24:52 +00:00
Fix language detection error
The root cause was load_installed_languages() of argostranslate being called at the top of the file instead of inside a function, this caused the list of installed languages to incorrectly be returned as an empty list.
This commit is contained in:
parent
bcf051b7ff
commit
e23b96f1da
2 changed files with 9 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue