LibreOffice plugin to pipe whole Writer documents through Google Translate, that ought to keep most of the page formatting.

⌈⌋ ⎇ branch:  PageTranslate


Artifact [dcc9993422]

Artifact dcc9993422126a586fdee4459f6e77ac967e1693:

  • File test/deepl.py — part of check-in [00e5bb6299] at 2022-10-22 22:17:32 on branch trunk — compact via fixture (user: mario size: 573)

import pytest, requests.exceptions, re, os
import translationbackends as tb


def hello(params):
    t = tb.DeeplApi(**params)
    assert t.translate("Hilfe") == "Help"

def cake(params):
    t = tb.DeeplApi(**params)
    assert t.translate("Der Kuchen wird kalt.") == "The cake is getting cold."

def deepl_web(params):
    del params["api_key"]
    t = tb.DeeplWeb(**params)
    try:
        assert t.translate("Hallo Welt.") == "Hello, world."
    except requests.exceptions.HTTPError as exc:
        if not re.match('429 Client Error', str(exc)):
            raise exc