File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -801,13 +801,25 @@ def create_full_page_title(
801801
802802
803803def 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 ))
You can’t perform that action at this time.
0 commit comments