1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-11-04 23:10:13 +01:00

Catch unknown language

This commit is contained in:
Piero Toffanin 2021-03-12 10:53:09 -05:00
parent 4875177f68
commit 79224edfe4

View File

@ -1,7 +1,7 @@
import string
from argostranslate import translate
from polyglot.detect.base import Detector
from polyglot.detect.base import Detector, UnknownLanguage
from polyglot.transliteration.base import Transliterator
@ -22,7 +22,10 @@ def detect_languages(text):
# get the candidates
candidates = []
for t in text:
candidates.extend(Detector(t).languages)
try:
candidates.extend(Detector(t).languages)
except UnknownLanguage as e:
pass
# total read bytes of the provided text
read_bytes_total = sum(c.read_bytes for c in candidates)