22
22
keyring_key_name = env_auth_key
23
23
24
24
25
- def action_usage (translator : deepl .Translator ):
25
+ def action_usage (deepl_client : deepl .DeepLClient ):
26
26
"""Action function for the usage command."""
27
- usage_result = translator .get_usage ()
27
+ usage_result = deepl_client .get_usage ()
28
28
print (usage_result )
29
29
30
30
31
- def action_languages (translator : deepl .Translator , glossary : bool ):
31
+ def action_languages (deepl_client : deepl .DeepLClient , glossary : bool ):
32
32
"""Action function for the languages command."""
33
33
if glossary :
34
- glossary_languages = translator .get_glossary_languages ()
34
+ glossary_languages = deepl_client .get_glossary_languages ()
35
35
print ("Language pairs supported for glossaries: (source, target)" )
36
36
for language_pair in glossary_languages :
37
37
print (f"{ language_pair .source_lang } , { language_pair .target_lang } " )
38
38
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 ()
41
41
42
42
print ("Source languages available:" )
43
43
for language in source_languages :
@@ -51,7 +51,7 @@ def action_languages(translator: deepl.Translator, glossary: bool):
51
51
52
52
53
53
def action_document (
54
- translator : deepl .Translator ,
54
+ deepl_client : deepl .DeepLClient ,
55
55
file : List [str ],
56
56
dest : str ,
57
57
output_format : Optional [str ],
@@ -70,13 +70,13 @@ def action_document(
70
70
else (os .path .splitext (this_file )[0 ] + "." + output_format )
71
71
)
72
72
output_path = os .path .join (dest , os .path .basename (outfile_name ))
73
- translator .translate_document_from_filepath (
73
+ deepl_client .translate_document_from_filepath (
74
74
this_file , output_path , ** kwargs
75
75
)
76
76
77
77
78
78
def action_text (
79
- translator : deepl .Translator ,
79
+ deepl_client : deepl .DeepLClient ,
80
80
show_detected_source : bool = False ,
81
81
show_billed_characters : Optional [bool ] = None ,
82
82
show_model_type_used : Optional [bool ] = None ,
@@ -88,7 +88,7 @@ def action_text(
88
88
# specify model_type so API includes model_type_used response parameter
89
89
kwargs ["model_type" ] = deepl .ModelType .LATENCY_OPTIMIZED
90
90
91
- translation = translator .translate_text (** kwargs )
91
+ translation = deepl_client .translate_text (** kwargs )
92
92
output_list = (
93
93
translation if isinstance (translation , List ) else [translation ]
94
94
)
@@ -114,11 +114,11 @@ def action_text(
114
114
115
115
116
116
def action_rephrase (
117
- translator : deepl .Translator ,
117
+ deepl_client : deepl .DeepLClient ,
118
118
** kwargs ,
119
119
):
120
120
"""Action function for the rephrase command."""
121
- improvement = translator .rephrase_text (** kwargs )
121
+ improvement = deepl_client .rephrase_text (** kwargs )
122
122
output_list = (
123
123
improvement if isinstance (improvement , List ) else [improvement ]
124
124
)
@@ -127,17 +127,17 @@ def action_rephrase(
127
127
128
128
129
129
def action_glossary (
130
- translator : deepl .Translator ,
130
+ deepl_client : deepl .DeepLClient ,
131
131
subcommand : str ,
132
132
** kwargs ,
133
133
):
134
134
# 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 )
136
136
pass
137
137
138
138
139
139
def action_glossary_create (
140
- translator : deepl .Translator , entry_list , file , csv , ** kwargs
140
+ deepl_client : deepl .DeepLClient , entry_list , file , csv , ** kwargs
141
141
):
142
142
term_separator = None
143
143
if file :
@@ -158,15 +158,15 @@ def action_glossary_create(
158
158
)
159
159
160
160
if csv :
161
- glossary = translator .create_glossary_from_csv (
161
+ glossary = deepl_client .create_glossary_from_csv (
162
162
csv_data = content , ** kwargs
163
163
)
164
164
else :
165
165
if term_separator :
166
166
entry_dict = deepl .convert_tsv_to_dict (content , term_separator )
167
167
else :
168
168
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 )
170
170
171
171
print (f"Created { glossary } " )
172
172
print_glossaries ([glossary ])
@@ -208,26 +208,26 @@ def print_glossaries(glossaries):
208
208
)
209
209
210
210
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 ()
213
213
print_glossaries (glossaries )
214
214
215
215
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 )
218
218
print_glossaries ([glossary ])
219
219
220
220
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 )
223
223
print (deepl .convert_dict_to_tsv (glossary_entries ))
224
224
225
225
226
226
def action_glossary_delete (
227
- translator : deepl .Translator , glossary_id_list : str
227
+ deepl_client : deepl .DeepLClient , glossary_id_list : str
228
228
):
229
229
for glossary_id in glossary_id_list :
230
- translator .delete_glossary (glossary_id )
230
+ deepl_client .delete_glossary (glossary_id )
231
231
print (f"Glossary with ID { glossary_id } successfully deleted." )
232
232
233
233
@@ -641,7 +641,7 @@ def main(args=None, prog_name=None):
641
641
642
642
# Note: the get_languages() call to verify language codes is skipped
643
643
# because the CLI makes one API call per execution.
644
- translator = deepl .Translator (
644
+ deepl_client = deepl .DeepLClient (
645
645
auth_key = auth_key ,
646
646
server_url = server_url ,
647
647
proxy = proxy_url ,
@@ -671,7 +671,7 @@ def main(args=None, prog_name=None):
671
671
args = vars (args )
672
672
# Call action function corresponding to command with remaining args
673
673
command = args .pop ("command" )
674
- globals ()[f"action_{ command } " ](translator , ** args )
674
+ globals ()[f"action_{ command } " ](deepl_client , ** args )
675
675
676
676
except Exception as exception :
677
677
sys .stderr .write (f"Error: { exception } \n " )
0 commit comments