mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-11-21 23:41:01 +00:00
Catch unknown language
This commit is contained in:
parent
4875177f68
commit
79224edfe4
1 changed files with 5 additions and 2 deletions
|
@ -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:
|
||||||
candidates.extend(Detector(t).languages)
|
try:
|
||||||
|
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 a new issue