From 79224edfe4dd2e30b16fda339419ab61d088eb4c Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 12 Mar 2021 10:53:09 -0500 Subject: [PATCH] Catch unknown language --- app/language.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/language.py b/app/language.py index e6f3613..e7a2d49 100644 --- a/app/language.py +++ b/app/language.py @@ -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)