Skip to content

Commit 6727ec6

Browse files
committed
rework of osw.data.import_utility.translate_list_with_deepl
1 parent 0330c33 commit 6727ec6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/osw/data/import_utility.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,13 +801,25 @@ def create_full_page_title(
801801

802802

803803
def translate_list_with_deepl(
804-
seq: list, credentials_file_path: Union[str, Path] = None
805-
) -> list:
804+
seq: list,
805+
credentials_file_path: Union[str, Path] = None,
806+
target_lang: str = "EN-US",
807+
translations: dict = None,
808+
) -> dict:
806809
"""Translates a list of strings with DeepL."""
807810
if credentials_file_path is None:
808811
credentials_file_path = CREDENTIALS_FILE_PATH_DEFAULT
812+
if translations is None:
813+
translations = {}
809814
domains, accounts = wt.read_domains_from_credentials_file(credentials_file_path)
810815
domain = "api-free.deepl.com"
811816
auth = accounts[domain]["password"]
812817
translator = deepl.Translator(auth)
813-
return [translator.translate_text(ele, target_lang="EN-US").text for ele in seq]
818+
819+
translated = [
820+
translator.translate_text(ele, target_lang=target_lang).text
821+
if ele not in translations.keys()
822+
else translations.get(ele)
823+
for ele in seq
824+
]
825+
return dict(zip(seq, translated))

0 commit comments

Comments
 (0)