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

⌈⌋ ⎇ branch:  PageTranslate


Check-in [891ce56de3]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix from="auto"/"select" from sticking around
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 891ce56de37cc901fc10506e60e5f483c6addfa9
User & Date: mario 2021-02-10 16:35:22
Context
2021-02-10
16:36
overwrite self.params["from"] on each init (becasue it's a class property) check-in: 5c19793b64 user: mario tags: trunk
16:35
Fix from="auto"/"select" from sticking around check-in: 891ce56de3 user: mario tags: trunk
2021-02-09
16:27
Use world map for new menu entry "From âžœ To 🗺<" check-in: 9b23b4db86 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pythonpath/translationbackends.py.

312
313
314
315
316
317
318
319

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334



335






336
337
338
339
340
341
342
# usability nightmare.
#
# doc:
#   https://mymemory.translated.net/doc/spec.php
# errs:
#   'PLEASE SELECT TWO DISTINCT LANGUAGES'
#   'INVALID EMAIL PROVIDED'
#   "'AUTO' IS AN INVALID SOURCE LANGUAGE . EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"

#
class mymemory(google):

    def __init__(self, params={}):
        self.params = params  # config+argparse
        self.max_len = 500
        self.rx_split = rx_split500
        try:
            import langdetect
            self.lang = langdetect.detect
        except:
            log.warning("`pip install langdetect` for best results\n"+format_exc())

    # API    
    def fetch(self, text, lang="en", src_lang="en"):



        src_lang = self.params.get("from") or self.lang(text)






        url = "https://api.mymemory.translated.net/get?q=%s&langpair=%s|%s&of=json&mt=1" % (
            quote_plus(text.encode("utf-8")), src_lang, lang
        )
        if self.params.get("email"):
            url = url + "&de=" + self.params["email"]
        # any exceptions are covered in main
        j = http.get(url).content.decode("utf-8")







|
>















>
>
>
|
>
>
>
>
>
>







312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# usability nightmare.
#
# doc:
#   https://mymemory.translated.net/doc/spec.php
# errs:
#   'PLEASE SELECT TWO DISTINCT LANGUAGES'
#   'INVALID EMAIL PROVIDED'
#   'AUTO' IS AN INVALID SOURCE LANGUAGE . EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"
#   'SELECT' IS AN INVALID SOURCE LANGUAGE . EXAMPLE: LANGPAIR=EN|IT USING 2 LETTER ISO OR RFC3066 LIKE ZH-CN. ALMOST ALL LANGUAGES SUPPORTED BUT SOME MAY HAVE NO CONTENT"
#
class mymemory(google):

    def __init__(self, params={}):
        self.params = params  # config+argparse
        self.max_len = 500
        self.rx_split = rx_split500
        try:
            import langdetect
            self.lang = langdetect.detect
        except:
            log.warning("`pip install langdetect` for best results\n"+format_exc())

    # API    
    def fetch(self, text, lang="en", src_lang="en"):
        #@todo: this is absolutely the wrong place for language detection,
        #  need more consistent parameter signatures all around
        if self.params.get("from") and self.params["from"] not in ("", "auto", "select"):
            src_lang = self.params["from"]
        else:
            src_lang = self.lang(text)
        if lang == src_lang:
            log.info("Skipping "+src_lang+"|"+lang)
            return text
        # call
        url = "https://api.mymemory.translated.net/get?q=%s&langpair=%s|%s&of=json&mt=1" % (
            quote_plus(text.encode("utf-8")), src_lang, lang
        )
        if self.params.get("email"):
            url = url + "&de=" + self.params["email"]
        # any exceptions are covered in main
        j = http.get(url).content.decode("utf-8")