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

βŒˆβŒ‹ βŽ‡ branch:  PageTranslate


Check-in [57703cade1]

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

Overview
Comment:Introduce 🏴 button configuration to change default language/behaviour.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 57703cade1bbaa1b91662202fa916379ca95cf6a
User & Date: mario 2021-05-15 16:26:55
Context
2021-05-15
16:27
Update notes on PONS and button config. check-in: 2bb2861a0a user: mario tags: trunk
16:26
Introduce 🏴 button configuration to change default language/behaviour. check-in: 57703cade1 user: mario tags: trunk
16:21
Transform OptionsPageURL= into code; switching to our dialog still non-functional. check-in: 93f1a54882 user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to OptionsDialog.xdl.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46










47
48
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="OptionsPageTranslate" dlg:left="110" dlg:top="50" dlg:width="283" dlg:height="258" dlg:help-url="HIDID" dlg:closeable="true" dlg:moveable="true" dlg:title="Title" dlg:withtitlebar="false">
 <dlg:styles>
  <dlg:style dlg:style-id="0" dlg:font-height="8"/>
  <dlg:style dlg:style-id="1" dlg:font-height="8" dlg:font-underline="single"/>
 </dlg:styles>
 <dlg:bulletinboard>
  <dlg:textfield dlg:id="api_key" dlg:tab-index="4" dlg:left="172" dlg:top="30" dlg:width="75" dlg:height="10" dlg:help-text="Key required for DeepL, Microsoft Translator, or Google Translate API (not implemented here)" dlg:help-url="HIDID"/>
  <dlg:checkbox dlg:id="frames" dlg:tab-index="1" dlg:left="20" dlg:top="102" dlg:width="100" dlg:height="10" dlg:help-text="Traverse subdocuments (frames / floating frames) as well" dlg:help-url="HIDID" dlg:value="also iterate over TextFrames" dlg:checked="false"/>
  <dlg:checkbox dlg:id="quick" dlg:tab-index="0" dlg:left="20" dlg:top="89" dlg:width="111" dlg:height="10" dlg:help-text="Temporary placeholders instead of iterating over newline breaks. (Only tested with Google Translate. Might screw up others.)" dlg:help-url="HIDID" dlg:value="quick paragraph linebreak handling" dlg:checked="false"/>
  <dlg:checkbox dlg:id="debug" dlg:tab-index="3" dlg:left="20" dlg:top="128" dlg:width="100" dlg:height="10" dlg:help-text="Log file in /tmp/pagetranslate-libreoffice.txt" dlg:help-url="HIDID" dlg:value="additonal debugging" dlg:checked="true"/>
  <dlg:textfield dlg:id="cmd" dlg:tab-index="6" dlg:left="172" dlg:top="74" dlg:width="75" dlg:height="10" dlg:help-text="Command to run, use `{}` as placeholder for text section" dlg:help-url="HIDID"/>
  <dlg:textfield dlg:id="email" dlg:tab-index="5" dlg:left="172" dlg:top="52" dlg:width="75" dlg:height="10" dlg:help-text="MyMemory asks for an email addres (does not require it)" dlg:help-url="HIDID"/>
  <dlg:checkbox dlg:id="slow" dlg:tab-index="2" dlg:left="20" dlg:top="115" dlg:width="109" dlg:height="10" dlg:help-text="Split sentences on formatting prior translation (= more roundtrips, less cohesive sentence structure / translation)" dlg:help-url="HIDID" dlg:value="slow mode (more inline formatting)" dlg:checked="false"/>
  <dlg:fixedline dlg:id="FixedLine1" dlg:tab-index="7" dlg:left="15" dlg:top="76" dlg:width="110" dlg:height="8" dlg:value="Options"/>
  <dlg:fixedline dlg:id="FixedLine3" dlg:tab-index="8" dlg:left="15" dlg:top="15" dlg:width="110" dlg:height="8" dlg:value="Service"/>
  <dlg:fixedline dlg:id="FixedLine2" dlg:tab-index="9" dlg:left="137" dlg:top="15" dlg:width="110" dlg:height="8" dlg:value="Parameters"/>
  <dlg:fixedline dlg:id="Label1" dlg:tab-index="10" dlg:left="140" dlg:top="30" dlg:width="23" dlg:height="8" dlg:value="API key "/>
  <dlg:fixedline dlg:id="Label2" dlg:tab-index="11" dlg:left="140" dlg:top="52" dlg:width="28" dlg:height="8" dlg:printable="false" dlg:value="Email adr "/>
  <dlg:fixedline dlg:id="Label3" dlg:tab-index="12" dlg:left="140" dlg:top="74" dlg:width="30" dlg:height="8" dlg:value="Command "/>
  <dlg:menulist dlg:id="backend" dlg:tab-index="13" dlg:left="20" dlg:top="30" dlg:width="105" dlg:height="14" dlg:help-text="Which translation service to use. (Some might require an API key, or email address.)" dlg:spin="true" dlg:linecount="16">
   <dlg:menupopup>
    <dlg:menuitem dlg:value="Google Translate" dlg:help-text="default"/>
    <dlg:menuitem dlg:value="MyMemory"/>
    <dlg:menuitem dlg:value="PONS Text Translation"/>
    <dlg:menuitem dlg:value="command line tool"/>
    <dlg:menuitem dlg:value="DeepL API"/>
    <dlg:menuitem dlg:value="DeepL Free API"/>
    <dlg:menuitem dlg:value="DeepL web interface"/>
    <dlg:menuitem dlg:value="Microsoft Translator (T-P)"/>
................................................................................
    <dlg:menuitem dlg:value="Yandex Translation (D-T)"/>
    <dlg:menuitem dlg:value="Pons Dictionary (D-T)"/>
    <dlg:menuitem dlg:value="Linguee Dictionary (D-T)"/>
    <dlg:menuitem dlg:value="D-T: DeepL Free API"/>
    <dlg:menuitem dlg:value="D-T: Google Translate"/>
   </dlg:menupopup>
  </dlg:menulist>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label4" dlg:tab-index="14" dlg:left="173" dlg:top="42" dlg:width="65" dlg:height="6" dlg:value="for DeepL / Microsoft / QCRI       "/>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label5" dlg:tab-index="15" dlg:left="173" dlg:top="64" dlg:width="32" dlg:height="6" dlg:value="for MyMemory  "/>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label6" dlg:tab-index="16" dlg:left="173" dlg:top="87" dlg:width="55" dlg:height="6" dlg:value="CLI program + arguments"/>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label7" dlg:tab-index="17" dlg:left="22" dlg:top="48" dlg:width="104" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="See                    on how the translation services             &#x0a;"/>
  <dlg:fixedline dlg:style-id="0" dlg:id="FixedLine4" dlg:tab-index="18" dlg:left="22" dlg:top="55" dlg:width="104" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="differ in behaviour and which options may apply.         "/>
  <dlg:fixedline dlg:style-id="0" dlg:id="FixedLine5" dlg:tab-index="19" dlg:left="22" dlg:top="62" dlg:width="104" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="Some do require an additional Python extension.               &#x0a;"/>
  <dlg:fixedline dlg:style-id="1" dlg:id="FixedLine6" dlg:tab-index="20" dlg:left="31" dlg:top="48" dlg:width="22" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="help pages"/>










 </dlg:bulletinboard>
</dlg:window>







|



|
|



|
|
|
|


|







 







|
|
|
|



>
>
>
>
>
>
>
>
>
>


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
..
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="OptionsPageTranslate" dlg:left="110" dlg:top="50" dlg:width="283" dlg:height="258" dlg:help-url="HIDID" dlg:closeable="true" dlg:moveable="true" dlg:title="Title" dlg:withtitlebar="false">
 <dlg:styles>
  <dlg:style dlg:style-id="0" dlg:font-height="8"/>
  <dlg:style dlg:style-id="1" dlg:font-height="8" dlg:font-underline="single"/>
 </dlg:styles>
 <dlg:bulletinboard>
  <dlg:textfield dlg:id="api_key" dlg:tab-index="4" dlg:left="177" dlg:top="30" dlg:width="75" dlg:height="10" dlg:help-text="Key required for DeepL, Microsoft Translator, or Google Translate API (not implemented here)" dlg:help-url="HIDID"/>
  <dlg:checkbox dlg:id="frames" dlg:tab-index="1" dlg:left="20" dlg:top="102" dlg:width="100" dlg:height="10" dlg:help-text="Traverse subdocuments (frames / floating frames) as well" dlg:help-url="HIDID" dlg:value="also iterate over TextFrames" dlg:checked="false"/>
  <dlg:checkbox dlg:id="quick" dlg:tab-index="0" dlg:left="20" dlg:top="89" dlg:width="111" dlg:height="10" dlg:help-text="Temporary placeholders instead of iterating over newline breaks. (Only tested with Google Translate. Might screw up others.)" dlg:help-url="HIDID" dlg:value="quick paragraph linebreak handling" dlg:checked="false"/>
  <dlg:checkbox dlg:id="debug" dlg:tab-index="3" dlg:left="20" dlg:top="128" dlg:width="100" dlg:height="10" dlg:help-text="Log file in /tmp/pagetranslate-libreoffice.txt" dlg:help-url="HIDID" dlg:value="additonal debugging" dlg:checked="true"/>
  <dlg:textfield dlg:id="cmd" dlg:tab-index="6" dlg:left="177" dlg:top="74" dlg:width="75" dlg:height="10" dlg:help-text="Command to run, use `{}` as placeholder for text section" dlg:help-url="HIDID"/>
  <dlg:textfield dlg:id="email" dlg:tab-index="5" dlg:left="177" dlg:top="52" dlg:width="75" dlg:height="10" dlg:help-text="MyMemory asks for an email addres (does not require it)" dlg:help-url="HIDID"/>
  <dlg:checkbox dlg:id="slow" dlg:tab-index="2" dlg:left="20" dlg:top="115" dlg:width="109" dlg:height="10" dlg:help-text="Split sentences on formatting prior translation (= more roundtrips, less cohesive sentence structure / translation)" dlg:help-url="HIDID" dlg:value="slow mode (more inline formatting)" dlg:checked="false"/>
  <dlg:fixedline dlg:id="FixedLine1" dlg:tab-index="7" dlg:left="15" dlg:top="76" dlg:width="110" dlg:height="8" dlg:value="Options"/>
  <dlg:fixedline dlg:id="FixedLine3" dlg:tab-index="8" dlg:left="15" dlg:top="15" dlg:width="110" dlg:height="8" dlg:value="Service"/>
  <dlg:fixedline dlg:id="FixedLine2" dlg:tab-index="9" dlg:left="139" dlg:top="15" dlg:width="110" dlg:height="8" dlg:value="Parameters"/>
  <dlg:fixedline dlg:id="Label1" dlg:tab-index="10" dlg:left="145" dlg:top="30" dlg:width="23" dlg:height="8" dlg:value="API key "/>
  <dlg:fixedline dlg:id="Label2" dlg:tab-index="11" dlg:left="145" dlg:top="52" dlg:width="28" dlg:height="8" dlg:printable="false" dlg:value="Email adr "/>
  <dlg:fixedline dlg:id="Label3" dlg:tab-index="12" dlg:left="145" dlg:top="74" dlg:width="30" dlg:height="8" dlg:value="Command "/>
  <dlg:menulist dlg:id="backend" dlg:tab-index="13" dlg:left="20" dlg:top="30" dlg:width="105" dlg:height="14" dlg:help-text="Which translation service to use. (Some might require an API key, or email address.)" dlg:spin="true" dlg:linecount="16">
   <dlg:menupopup>
    <dlg:menuitem dlg:value="Google Translate"/>
    <dlg:menuitem dlg:value="MyMemory"/>
    <dlg:menuitem dlg:value="PONS Text Translation"/>
    <dlg:menuitem dlg:value="command line tool"/>
    <dlg:menuitem dlg:value="DeepL API"/>
    <dlg:menuitem dlg:value="DeepL Free API"/>
    <dlg:menuitem dlg:value="DeepL web interface"/>
    <dlg:menuitem dlg:value="Microsoft Translator (T-P)"/>
................................................................................
    <dlg:menuitem dlg:value="Yandex Translation (D-T)"/>
    <dlg:menuitem dlg:value="Pons Dictionary (D-T)"/>
    <dlg:menuitem dlg:value="Linguee Dictionary (D-T)"/>
    <dlg:menuitem dlg:value="D-T: DeepL Free API"/>
    <dlg:menuitem dlg:value="D-T: Google Translate"/>
   </dlg:menupopup>
  </dlg:menulist>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label4" dlg:tab-index="14" dlg:left="178" dlg:top="42" dlg:width="65" dlg:height="6" dlg:value="for DeepL / Microsoft / QCRI       "/>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label5" dlg:tab-index="15" dlg:left="178" dlg:top="64" dlg:width="32" dlg:height="6" dlg:value="for MyMemory  "/>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label6" dlg:tab-index="16" dlg:left="178" dlg:top="87" dlg:width="55" dlg:height="6" dlg:value="CLI program + arguments"/>
  <dlg:fixedline dlg:style-id="0" dlg:id="Label7" dlg:tab-index="17" dlg:left="22" dlg:top="48" dlg:width="104" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="See help pages on how the translation services             &#x0a;"/>
  <dlg:fixedline dlg:style-id="0" dlg:id="FixedLine4" dlg:tab-index="18" dlg:left="22" dlg:top="55" dlg:width="104" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="differ in behaviour and which options may apply.         "/>
  <dlg:fixedline dlg:style-id="0" dlg:id="FixedLine5" dlg:tab-index="19" dlg:left="22" dlg:top="62" dlg:width="104" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="Some do require an additional Python extension.               &#x0a;"/>
  <dlg:fixedline dlg:style-id="1" dlg:id="FixedLine6" dlg:tab-index="20" dlg:left="31" dlg:top="48" dlg:width="22" dlg:height="7" dlg:help-url="vnd.sun.star.help://help/vnd.include-once.pagetranslate/config.xhp?Language=en&amp;System=UNIX&amp;UseDB=no" dlg:value="help pages"/>
  <dlg:fixedline dlg:id="FixedLine7" dlg:tab-index="21" dlg:left="139" dlg:top="103" dlg:width="110" dlg:height="8" dlg:value="🏴  Button "/>
  <dlg:combobox dlg:id="flag" dlg:tab-index="22" dlg:left="180" dlg:top="116" dlg:width="60" dlg:height="10" dlg:help-text="Can be any XY langauge code, or &quot;locale&quot; for System/Office langauge, &quot;paragraph&quot; to honor the language toolbar, or &quot;select&quot; to bring up the From→To dialog" dlg:value="locale" dlg:spin="true">
   <dlg:menupopup>
    <dlg:menuitem dlg:value="locale"/>
    <dlg:menuitem dlg:value="select"/>
    <dlg:menuitem dlg:value="paragraph"/>
    <dlg:menuitem dlg:value="en"/>
   </dlg:menupopup>
  </dlg:combobox>
  <dlg:fixedline dlg:id="FixedLine8" dlg:tab-index="23" dlg:left="145" dlg:top="117" dlg:width="27" dlg:height="8" dlg:help-text="Which language the 🏴 button defaults to" dlg:value="Language"/>
 </dlg:bulletinboard>
</dlg:window>

Changes to OptionsSchema.xcs.

31
32
33
34
35
36
37

38
39
40
41
        <prop oor:name="api_key" oor:type="xs:string"><value></value></prop>
        <prop oor:name="email" oor:type="xs:string"><value></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>







>




31
32
33
34
35
36
37
38
39
40
41
42
        <prop oor:name="api_key" oor:type="xs:string"><value></value></prop>
        <prop oor:name="email" oor:type="xs:string"><value></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>
        <prop oor:name="flag" oor:type="xs:string"><value>locale</value></prop>
      </group>
    </group>
  </component>
</oor:component-schema>