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:
parent
4875177f68
commit
79224edfe4
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user