2222keyring_key_name = env_auth_key
2323
2424
25- def action_usage (translator : deepl .Translator ):
25+ def action_usage (deepl_client : deepl .DeepLClient ):
2626 """Action function for the usage command."""
27- usage_result = translator .get_usage ()
27+ usage_result = deepl_client .get_usage ()
2828 print (usage_result )
2929
3030
31- def action_languages (translator : deepl .Translator , glossary : bool ):
31+ def action_languages (deepl_client : deepl .DeepLClient , glossary : bool ):
3232 """Action function for the languages command."""
3333 if glossary :
34- glossary_languages = translator .get_glossary_languages ()
34+ glossary_languages = deepl_client .get_glossary_languages ()
3535 print ("Language pairs supported for glossaries: (source, target)" )
3636 for language_pair in glossary_languages :
3737 print (f"{ language_pair .source_lang } , { language_pair .target_lang } " )
3838 else :
39- source_languages = translator .get_source_languages ()
40- target_languages = translator .get_target_languages ()
39+ source_languages = deepl_client .get_source_languages ()
40+ target_languages = deepl_client .get_target_languages ()
4141
4242 print ("Source languages available:" )
4343 for language in source_languages :
@@ -51,7 +51,7 @@ def action_languages(translator: deepl.Translator, glossary: bool):
5151
5252
5353def action_document (
54- translator : deepl .Translator ,
54+ deepl_client : deepl .DeepLClient ,
5555 file : List [str ],
5656 dest : str ,
5757 output_format : Optional [str ],
@@ -70,13 +70,13 @@ def action_document(
7070 else (os .path .splitext (this_file )[0 ] + "." + output_format )
7171 )
7272 output_path = os .path .join (dest , os .path .basename (outfile_name ))
73- translator .translate_document_from_filepath (
73+ deepl_client .translate_document_from_filepath (
7474 this_file , output_path , ** kwargs
7575 )
7676
7777
7878def action_text (
79- translator : deepl .Translator ,
79+ deepl_client : deepl .DeepLClient ,
8080 show_detected_source : bool = False ,
8181 show_billed_characters : Optional [bool ] = None ,
8282 show_model_type_used : Optional [bool ] = None ,
@@ -88,7 +88,7 @@ def action_text(
8888 # specify model_type so API includes model_type_used response parameter
8989 kwargs ["model_type" ] = deepl .ModelType .LATENCY_OPTIMIZED
9090
91- translation = translator .translate_text (** kwargs )
91+ translation = deepl_client .translate_text (** kwargs )
9292 output_list = (
9393 translation if isinstance (translation , List ) else [translation ]
9494 )
@@ -114,11 +114,11 @@ def action_text(
114114
115115
116116def action_rephrase (
117- translator : deepl .Translator ,
117+ deepl_client : deepl .DeepLClient ,
118118 ** kwargs ,
119119):
120120 """Action function for the rephrase command."""
121- improvement = translator .rephrase_text (** kwargs )
121+ improvement = deepl_client .rephrase_text (** kwargs )
122122 output_list = (
123123 improvement if isinstance (improvement , List ) else [improvement ]
124124 )
@@ -127,17 +127,17 @@ def action_rephrase(
127127
128128
129129def action_glossary (
130- translator : deepl .Translator ,
130+ deepl_client : deepl .DeepLClient ,
131131 subcommand : str ,
132132 ** kwargs ,
133133):
134134 # Call action function corresponding to command with remaining args
135- globals ()[f"action_glossary_{ subcommand } " ](translator , ** kwargs )
135+ globals ()[f"action_glossary_{ subcommand } " ](deepl_client , ** kwargs )
136136 pass
137137
138138
139139def action_glossary_create (
140- translator : deepl .Translator , entry_list , file , csv , ** kwargs
140+ deepl_client : deepl .DeepLClient , entry_list , file , csv , ** kwargs
141141):
142142 term_separator = None
143143 if file :
@@ -158,15 +158,15 @@ def action_glossary_create(
158158 )
159159
160160 if csv :
161- glossary = translator .create_glossary_from_csv (
161+ glossary = deepl_client .create_glossary_from_csv (
162162 csv_data = content , ** kwargs
163163 )
164164 else :
165165 if term_separator :
166166 entry_dict = deepl .convert_tsv_to_dict (content , term_separator )
167167 else :
168168 entry_dict = deepl .convert_tsv_to_dict (content )
169- glossary = translator .create_glossary (entries = entry_dict , ** kwargs )
169+ glossary = deepl_client .create_glossary (entries = entry_dict , ** kwargs )
170170
171171 print (f"Created { glossary } " )
172172 print_glossaries ([glossary ])
@@ -208,26 +208,26 @@ def print_glossaries(glossaries):
208208 )
209209
210210
211- def action_glossary_list (translator : deepl .Translator ):
212- glossaries = translator .list_glossaries ()
211+ def action_glossary_list (deepl_client : deepl .DeepLClient ):
212+ glossaries = deepl_client .list_glossaries ()
213213 print_glossaries (glossaries )
214214
215215
216- def action_glossary_get (translator : deepl .Translator , ** kwargs ):
217- glossary = translator .get_glossary (** kwargs )
216+ def action_glossary_get (deepl_client : deepl .DeepLClient , ** kwargs ):
217+ glossary = deepl_client .get_glossary (** kwargs )
218218 print_glossaries ([glossary ])
219219
220220
221- def action_glossary_entries (translator : deepl .Translator , glossary_id ):
222- glossary_entries = translator .get_glossary_entries (glossary = glossary_id )
221+ def action_glossary_entries (deepl_client : deepl .DeepLClient , glossary_id ):
222+ glossary_entries = deepl_client .get_glossary_entries (glossary = glossary_id )
223223 print (deepl .convert_dict_to_tsv (glossary_entries ))
224224
225225
226226def action_glossary_delete (
227- translator : deepl .Translator , glossary_id_list : str
227+ deepl_client : deepl .DeepLClient , glossary_id_list : str
228228):
229229 for glossary_id in glossary_id_list :
230- translator .delete_glossary (glossary_id )
230+ deepl_client .delete_glossary (glossary_id )
231231 print (f"Glossary with ID { glossary_id } successfully deleted." )
232232
233233
@@ -641,7 +641,7 @@ def main(args=None, prog_name=None):
641641
642642 # Note: the get_languages() call to verify language codes is skipped
643643 # because the CLI makes one API call per execution.
644- translator = deepl .Translator (
644+ deepl_client = deepl .DeepLClient (
645645 auth_key = auth_key ,
646646 server_url = server_url ,
647647 proxy = proxy_url ,
@@ -671,7 +671,7 @@ def main(args=None, prog_name=None):
671671 args = vars (args )
672672 # Call action function corresponding to command with remaining args
673673 command = args .pop ("command" )
674- globals ()[f"action_{ command } " ](translator , ** args )
674+ globals ()[f"action_{ command } " ](deepl_client , ** args )
675675
676676 except Exception as exception :
677677 sys .stderr .write (f"Error: { exception } \n " )
0 commit comments