1
0
mirror of https://github.com/LibreTranslate/LibreTranslate.git synced 2024-09-29 08:00:18 +02:00

Fix some warnings

This commit is contained in:
Piero Toffanin 2023-10-30 00:09:52 -04:00
parent 6c5fa2a4ee
commit 522b8b03d7
2 changed files with 4 additions and 4 deletions

View File

@ -17,7 +17,8 @@ def load_detector(langcodes = ()):
for lc in langcodes: for lc in langcodes:
try: try:
languages.append(linguars.Language.from_iso_code_639_1(lc)) languages.append(linguars.Language.from_iso_code_639_1(lc))
except: except Exception as e:
print(f"{lc} is not supported by lingua")
pass # Not supported pass # Not supported
return linguars.LanguageDetector(languages=languages) return linguars.LanguageDetector(languages=languages)
@ -29,7 +30,6 @@ class Detector:
def detect(self, text): def detect(self, text):
top_3_choices = self.detector.confidence(text)[:3] top_3_choices = self.detector.confidence(text)[:3]
print(top_3_choices)
if top_3_choices[0][1] == 0: if top_3_choices[0][1] == 0:
return [Language("en", 0)] return [Language("en", 0)]
return [Language(lang.iso_code_639_1, round(conf * 100)) for lang, conf in top_3_choices] return [Language(lang.iso_code_639_1, round(conf * 100)) for lang, conf in top_3_choices]

View File

@ -37,8 +37,8 @@ def detect_languages(text):
for i in range(len(d)): for i in range(len(d)):
d[i].text_length = len(t) d[i].text_length = len(t)
candidates.extend(d) candidates.extend(d)
except: except Exception as e:
pass print(str(e))
# total read bytes of the provided text # total read bytes of the provided text
text_length_total = sum(c.text_length for c in candidates) text_length_total = sum(c.text_length for c in candidates)