@@ -43,38 +43,121 @@ class DeepLCLI:
4343
4444 fr_langs : ClassVar [set [str ]] = {
4545 # "auto",
46+ "ace" ,
47+ "af" ,
48+ "an" ,
4649 "ar" ,
50+ "as" ,
51+ "ay" ,
52+ "az" ,
53+ "ba" ,
54+ "be" ,
4755 "bg" ,
48- "zh" ,
56+ "bho" ,
57+ "bn" ,
58+ "br" ,
59+ "bs" ,
60+ "ca" ,
61+ "ceb" ,
62+ "ckb" ,
4963 "cs" ,
64+ "cy" ,
5065 "da" ,
51- "nl" ,
66+ "de" ,
67+ "el" ,
5268 "en" ,
69+ "eo" ,
70+ "es" ,
5371 "et" ,
72+ "eu" ,
73+ "fa" ,
5474 "fi" ,
5575 "fr" ,
56- "de" ,
57- "el" ,
76+ "ga" ,
77+ "gl" ,
78+ "gn" ,
79+ "gom" ,
80+ "gu" ,
81+ "ha" ,
82+ "he" ,
83+ "hi" ,
84+ "hr" ,
85+ "ht" ,
5886 "hu" ,
87+ "hy" ,
5988 "id" ,
89+ "ig" ,
90+ "is" ,
6091 "it" ,
6192 "ja" ,
93+ "jv" ,
94+ "ka" ,
95+ "kk" ,
96+ "kmr" ,
6297 "ko" ,
63- "lv" ,
98+ "ky" ,
99+ "la" ,
100+ "lb" ,
101+ "lmo" ,
102+ "ln" ,
64103 "lt" ,
104+ "lv" ,
105+ "mai" ,
106+ "mg" ,
107+ "mi" ,
108+ "mk" ,
109+ "ml" ,
110+ "mn" ,
111+ "mr" ,
112+ "ms" ,
113+ "mt" ,
114+ "my" ,
65115 "nb" ,
116+ "ne" ,
117+ "nl" ,
118+ "oc" ,
119+ "om" ,
120+ "pa" ,
121+ "pag" ,
122+ "pam" ,
66123 "pl" ,
124+ "prs" ,
125+ "ps" ,
67126 "pt" ,
127+ "qu" ,
68128 "ro" ,
69129 "ru" ,
130+ "sa" ,
131+ "scn" ,
70132 "sk" ,
71133 "sl" ,
72- "es" ,
134+ "sq" ,
135+ "sr" ,
136+ "st" ,
137+ "su" ,
73138 "sv" ,
139+ "sw" ,
140+ "ta" ,
141+ "te" ,
142+ "tg" ,
143+ "tk" ,
144+ "tl" ,
145+ "tn" ,
74146 "tr" ,
147+ "ts" ,
148+ "tt" ,
75149 "uk" ,
150+ "ur" ,
151+ "uz" ,
152+ "vi" ,
153+ "wo" ,
154+ "xh" ,
155+ "yi" ,
156+ "yue" ,
157+ "zh" ,
158+ "zu" ,
76159 }
77- to_langs = fr_langs | {"zh-hans" , "zh-hant" , "en-us" , "en-gb" , "pt-pt" , "pt-br" } - {
160+ to_langs = fr_langs | {"zh-hans" , "zh-hant" , "en-us" , "en-gb" , "pt-pt" , "pt-br" , "es-419" } - {
78161 "auto" ,
79162 "zh" ,
80163 "en" ,
@@ -133,8 +216,7 @@ def translate(self, script: str) -> str:
133216 script = self .__sanitize_script (script )
134217
135218 # run in the current thread
136- loop = asyncio .get_event_loop ()
137- return loop .run_until_complete (self .__translate (script ))
219+ return asyncio .run (self .__translate (script ))
138220
139221 def translate_async (self , script : str ) -> Coroutine [Any , Any , str ]:
140222 """Translate script asynchronously.
@@ -201,8 +283,8 @@ async def __translate(self, script: str) -> str: # noqa: C901, PLR0915
201283 raise DeepLCLIPageLoadError (msg ) from e
202284
203285 if self .use_dom_submit :
204- # banner prevents clicking on language buttons, close the banner first
205- await page .click ("button[data-testid=cookie-banner-strict-accept-all]" )
286+ with contextlib . suppress ( PlaywrightError ):
287+ await page .click ("button[data-testid=cookie-banner-strict-accept-all]" )
206288 # we also expect the Chrome extension banner to show up
207289 with contextlib .suppress (PlaywrightError ):
208290 await page .wait_for_function (
@@ -230,7 +312,7 @@ async def __translate(self, script: str) -> str: # noqa: C901, PLR0915
230312 .get_by_test_id (
231313 f"translator-lang-option-{ self .fr_lang } " ,
232314 )
233- .dispatch_event ("click" )
315+ .first . dispatch_event ("click" )
234316 )
235317 await page .locator (
236318 "button[data-testid=translator-target-lang-btn]" ,
@@ -240,7 +322,7 @@ async def __translate(self, script: str) -> str: # noqa: C901, PLR0915
240322 .get_by_test_id (
241323 f"translator-lang-option-{ self .to_lang } " ,
242324 )
243- .dispatch_event ("click" )
325+ .first . dispatch_event ("click" )
244326 )
245327 # fill in the form of translating script
246328 await page .fill (
@@ -255,6 +337,7 @@ async def __translate(self, script: str) -> str: # noqa: C901, PLR0915
255337 () => document.querySelector(
256338 'd-textarea[aria-labelledby=translation-target-heading]')?.value?.length > 0
257339 """ ,
340+ timeout = self .timeout ,
258341 )
259342 except PlaywrightError as e :
260343 msg = f"Time limit exceeded. ({ self .timeout } ms)"
@@ -276,7 +359,7 @@ async def __translate(self, script: str) -> str: # noqa: C901, PLR0915
276359 # Since the site may not output all lines at once, we wait until each line is finished
277360 # and then add it to the list of translated lines
278361 translated_lines = []
279- for line_index in range (line_count - 1 ):
362+ for line_index in range (line_count ):
280363 try :
281364 await page .wait_for_function (
282365 f"""
@@ -344,7 +427,7 @@ def __sanitize_script(self, script: str) -> str:
344427 async def __get_browser (self , p : Playwright ) -> Browser :
345428 """Launch browser executable and get playwright browser object."""
346429 return await p .chromium .launch (
347- headless = True , # for debug, change into ` False`
430+ headless = False ,
348431 args = [
349432 "--no-sandbox" ,
350433 "--single-process" if os .name != "nt" else "" ,
0 commit comments