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

⌈⌋ branch:  PageTranslate


Check-in [5a0ee83349]

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

Overview
Comment:Add default flags `-o -t {lang}` for cli backend.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:5a0ee8334907b2febff3fe0877403e521eb135f3
User & Date: mario 2020-06-10 05:08:32
Context
2020-06-10
05:09
Introduce crude help file for config options. check-in: a2bf060c6d user: mario tags: trunk
05:08
Add default flags `-o -t {lang}` for cli backend. check-in: 5a0ee83349 user: mario tags: trunk
2020-06-02
16:59
Rewrite TextPortion handling (slow mode) according to reality. (.supportsService("XEnumeration") won't work, and getString/setString on TextPortion) However, formatting bleeds into adjoining text segments, so probably a useless operation mode. (Machine translations are expectedly worse.) check-in: 46943916e1 user: mario tags: trunk
Changes

Changes to OptionsSchema.xcs.

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        <prop oor:name="deepl_web" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="deepl_api" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="api_key" oor:type="xs:string"><value></value></prop>
        <prop oor:name="microsoft" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="mymemory" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="email" oor:type="xs:string"><value></value></prop>
        <prop oor:name="cli" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="cmd" oor:type="xs:string"><value>translate-cli -t {lang} {text}</value></prop>
        <prop oor:name="quick" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="frames" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="slow" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="debug" oor:type="xs:short"><value>1</value></prop>
      </group>
    </group>
  </component>
</oor:component-schema>







|








36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
        <prop oor:name="deepl_web" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="deepl_api" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="api_key" oor:type="xs:string"><value></value></prop>
        <prop oor:name="microsoft" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="mymemory" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="email" oor:type="xs:string"><value></value></prop>
        <prop oor:name="cli" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="cmd" oor:type="xs:string"><value>translate-cli -o -f auto -t {lang} {text}</value></prop>
        <prop oor:name="quick" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="frames" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="slow" oor:type="xs:short"><value>0</value></prop>
        <prop oor:name="debug" oor:type="xs:short"><value>1</value></prop>
      </group>
    </group>
  </component>
</oor:component-schema>

Changes to pagetranslate.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python
# encoding: utf-8
# api: uno
# type: callback
# category: language
# title: PageTranslate
# description: Action button to get whole Writer document translated
# version: 1.5.10
# state: beta
# author: mario
# url: https://fossil.include-once.org/pagetranslate/
# depends: python:requests (>= 2.5), python:translate
# pack: *.py, pythonpath/*.py, META-INF/*, pkg-desc, *.x*, icons/*
# license: GNU LGPL 2.1
# forked-from: TradutorLibreText (Claudemir de Almeida Rosa)
................................................................................
        deepl_web = 0,
        deepl_api = 0,
        api_key = "",
        microsoft = 0,
        mymemory = 0,
        email = "",
        cli = 0,
        cmd = "translate-cli -t {lang} {text}",
    )
    t = None   #= translationbackends.google(self.params)


    # gets instantiated as XJobExecutor by LibreOffice
    def __init__(self, ctx):
        log.info("init")







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python
# encoding: utf-8
# api: uno
# type: callback
# category: language
# title: PageTranslate
# description: Action button to get whole Writer document translated
# version: 1.5.66
# state: beta
# author: mario
# url: https://fossil.include-once.org/pagetranslate/
# depends: python:requests (>= 2.5), python:translate
# pack: *.py, pythonpath/*.py, META-INF/*, pkg-desc, *.x*, icons/*
# license: GNU LGPL 2.1
# forked-from: TradutorLibreText (Claudemir de Almeida Rosa)
................................................................................
        deepl_web = 0,
        deepl_api = 0,
        api_key = "",
        microsoft = 0,
        mymemory = 0,
        email = "",
        cli = 0,
        cmd = "translate-cli -o -f auto -t {lang} {text}",
    )
    t = None   #= translationbackends.google(self.params)


    # gets instantiated as XJobExecutor by LibreOffice
    def __init__(self, ctx):
        log.info("init")

Changes to pythonpath/translationbackends.py.

308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#
# Don't quote placeholders {}, {text} or {lang} in the command.
#
class cli(google):

    def __init__(self, params):
        self.params = params
        self.cmd = params.get("cmd", "translate-cli {}")

    # pipe text through external program
    def translate(self, text):
        if rx_empty.match(text) or not rx_letters.search(text):
            return text
        repl = {"{text}": text, "{lang}": self.params["lang"]}
        cmd = [arg.format(text, **repl) for arg in shlex.split(self.cmd)]







|







308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#
# Don't quote placeholders {}, {text} or {lang} in the command.
#
class cli(google):

    def __init__(self, params):
        self.params = params
        self.cmd = params.get("cmd", "translate-cli -o -f auto -t {lang} {text}")

    # pipe text through external program
    def translate(self, text):
        if rx_empty.match(text) or not rx_letters.search(text):
            return text
        repl = {"{text}": text, "{lang}": self.params["lang"]}
        cmd = [arg.format(text, **repl) for arg in shlex.split(self.cmd)]