eggplants / deepl-cli

DeepL Translator CLI (without API Key)
https://pypi.org/project/deepl-cli/
MIT License
254 stars 18 forks source link

Partial translation error #253

Open Medoo48 opened 3 weeks ago

Medoo48 commented 3 weeks ago

The latest update to the DeepL interface added a skeleton display for text that is still being translated. This creates a problem, because deepl-cli does not wait for the entire text to be translated, but copies it as soon as the length of the translated text is > 0 and thus the result contains an incomplete translation and ‘[...]’

I solved this problem in the following way:

res = str((await output_textbox.all_inner_texts())[0])
attempts=3
while "[...]" in res:
    time.sleep(20)
    res = str((await output_textbox.all_inner_texts())[0])
    attempts -= 1
    if attempts == 0:
        print("give up\n")
        break

Ideally, this should be checked in JS, but for some reason, my code doesn't work:

() => document.querySelector('d-textarea[aria-labelledby=translation-target-heading]')?.value?.length > 0 && ! document.querySelector('d-textarea[aria-labelledby=translation-target-heading]').value.includes("[...]")