mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-08-21 22:00:15 +02:00
Merge pull request #219 from ZenulAbidin/detect_fix
Fix language detection error
This commit is contained in:
commit
45649c3340
@ -102,7 +102,7 @@ def create_app(args):
|
|||||||
|
|
||||||
boot(args.load_only)
|
boot(args.load_only)
|
||||||
|
|
||||||
from app.language import languages
|
from app.language import load_languages
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
@ -111,6 +111,7 @@ def create_app(args):
|
|||||||
|
|
||||||
if not args.disable_files_translation:
|
if not args.disable_files_translation:
|
||||||
remove_translated_files.setup(get_upload_dir())
|
remove_translated_files.setup(get_upload_dir())
|
||||||
|
languages = load_languages()
|
||||||
|
|
||||||
# Map userdefined frontend languages to argos language object.
|
# Map userdefined frontend languages to argos language object.
|
||||||
if args.frontend_language_source == "auto":
|
if args.frontend_language_source == "auto":
|
||||||
|
@ -4,11 +4,11 @@ from argostranslate import translate
|
|||||||
from polyglot.detect.base import Detector, UnknownLanguage
|
from polyglot.detect.base import Detector, UnknownLanguage
|
||||||
from polyglot.transliteration.base import Transliterator
|
from polyglot.transliteration.base import Transliterator
|
||||||
|
|
||||||
languages = translate.load_installed_languages()
|
|
||||||
|
|
||||||
|
|
||||||
__lang_codes = [l.code for l in languages]
|
def load_languages():
|
||||||
|
languages = translate.load_installed_languages()
|
||||||
|
return languages
|
||||||
|
|
||||||
def detect_languages(text):
|
def detect_languages(text):
|
||||||
# detect batch processing
|
# detect batch processing
|
||||||
@ -32,6 +32,10 @@ def detect_languages(text):
|
|||||||
# 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)
|
||||||
|
|
||||||
|
# Load language codes
|
||||||
|
languages = load_languages()
|
||||||
|
__lang_codes = [l.code for l in languages]
|
||||||
|
|
||||||
# only use candidates that are supported by argostranslate
|
# only use candidates that are supported by argostranslate
|
||||||
candidate_langs = list(
|
candidate_langs = list(
|
||||||
filter(lambda l: l.text_length != 0 and l.code in __lang_codes, candidates)
|
filter(lambda l: l.text_length != 0 and l.code in __lang_codes, candidates)
|
||||||
|
Loading…
Reference in New Issue
Block a user