mirror of
https://github.com/LibreTranslate/LibreTranslate.git
synced 2024-12-18 08:27:03 +02:00
Add support for "auto" when translating files
This commit is contained in:
parent
2b74c57ffa
commit
db9f92a1c3
@ -830,7 +830,7 @@ def create_app(args):
|
||||
|
||||
src_lang = next(iter([l for l in languages if l.code == source_lang]), None)
|
||||
|
||||
if src_lang is None:
|
||||
if src_lang is None and source_lang != "auto":
|
||||
abort(400, description=_("%(lang)s is not supported", lang=source_lang))
|
||||
|
||||
tgt_lang = next(iter([l for l in languages if l.code == target_lang]), None)
|
||||
@ -852,6 +852,11 @@ def create_app(args):
|
||||
if char_limit > 0:
|
||||
request.req_cost = max(1, int(os.path.getsize(filepath) / char_limit))
|
||||
|
||||
if source_lang == "auto":
|
||||
src_texts = argostranslatefiles.get_texts(filepath)
|
||||
candidate_langs = detect_languages(src_texts)
|
||||
src_lang = candidate_langs[0]
|
||||
|
||||
translated_file_path = argostranslatefiles.translate_file(src_lang.get_translation(tgt_lang), filepath)
|
||||
translated_filename = os.path.basename(translated_file_path)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user