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

⌈⌋ ⎇ branch:  PageTranslate


Check-in [46943916e1]

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

Overview
Comment: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.)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 46943916e186531c89e2763b1ee37ea010ffb136
User & Date: mario 2020-06-02 16:59:09
Context
2020-06-10
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
2020-06-01
19:07
Implement deepl_web instanceId/sessId/cookie retrieval, still yields 429 though. Add {text} and {lang} placeholders for cli backend. check-in: d0a93e3bf3 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pagetranslate.py.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/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.5
# 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)







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/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)
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
                    text.setString(self.t.linebreakwise(text.getString())) # or .translate #linebreakwise
            # subdocuments?
            elif para.supportsService("com.sun.star.text.TextFrame"):
                log.debug("TextFrame.Enumeration…")
                self.traverse(para.getText().createEnumeration())
            # a paragraph can be further enumerated for text portions (same character/style attributes),
            # but that will obviously slow things down further / also complicate coherent translations
            elif slow and para.supportsService("com.sun.star.container.XEnumerationAccess"): # or just "com.sun.star.text.Paragraph"?
                self.traverse(para.createEnumeration(), slow=0)
            # normal flow text / paragraph
            elif para.supportsService("com.sun.star.text.TextContent"):
                text = para.getString()
                text = self.t.translate(text)
                para.setString(text)
            else:
                log.warning("Unsupported document element.")

    #-- iterate over DrawPages and TextShapes







|
|

|







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
                    text.setString(self.t.linebreakwise(text.getString())) # or .translate #linebreakwise
            # subdocuments?
            elif para.supportsService("com.sun.star.text.TextFrame"):
                log.debug("TextFrame.Enumeration…")
                self.traverse(para.getText().createEnumeration())
            # a paragraph can be further enumerated for text portions (same character/style attributes),
            # but that will obviously slow things down further / also complicate coherent translations
            elif slow and para.supportsService("com.sun.star.text.Paragraph"): # doesn't work with com.sun.star.container.XEnumerationAccess?
                self.traverse(para.createEnumeration(), slow=0)  # list of TextPortion`s
            # normal flow text / paragraph
            elif para.supportsService("com.sun.star.text.TextContent") or para.supportsService("com.sun.star.text.TextPortion"):
                text = para.getString()
                text = self.t.translate(text)
                para.setString(text)
            else:
                log.warning("Unsupported document element.")

    #-- iterate over DrawPages and TextShapes