1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-11-17 13:00:11 +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 import string
from argostranslate import translate from argostranslate import translate
from polyglot.detect.base import Detector from polyglot.detect.base import Detector, UnknownLanguage
from polyglot.transliteration.base import Transliterator from polyglot.transliteration.base import Transliterator
@ -22,7 +22,10 @@ def detect_languages(text):
# get the candidates # get the candidates
candidates = [] candidates = []
for t in text: for t in text:
try:
candidates.extend(Detector(t).languages) candidates.extend(Detector(t).languages)
except UnknownLanguage as e:
pass
# total read bytes of the provided text # total read bytes of the provided text
read_bytes_total = sum(c.read_bytes for c in candidates) read_bytes_total = sum(c.read_bytes for c in candidates)