From 2321ad09563b8f8ef07f39553ed77ed9fe4d288b Mon Sep 17 00:00:00 2001 From: zh-plus Date: Thu, 29 Feb 2024 11:08:26 +0800 Subject: [PATCH] Improve language detection process. --- openlrc/prompter.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openlrc/prompter.py b/openlrc/prompter.py index 9ef7f28..df854a8 100644 --- a/openlrc/prompter.py +++ b/openlrc/prompter.py @@ -179,8 +179,12 @@ def check_format(self, messages, content): translation_chunks[-2].extend(translation_chunks[-1]) translation_chunks.pop() - translated_langs = [self.lan_detector.detect_language_of(' '.join(chunk)).name.lower() - for chunk in translation_chunks] + translated_langs = [self.lan_detector.detect_language_of(' '.join(chunk)) for chunk in translation_chunks] + translated_langs = [lang.name.lower() for lang in translated_langs if lang] + + if not translated_langs: + # Cant detect language + return True # get the most common language translated_lang = max(set(translated_langs), key=translated_langs.count)