Check-in [7ad6ace92e]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | support all 4 new Deep-Translate backends, still needs some rework to omit "auto" source language |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
7ad6ace92e0dcda60d70b1b96f431207 |
User & Date: | mario 2021-05-13 05:28:06 |
Context
2021-05-13
| ||
15:41 | Expand D-T backend hooks, abbreviate any ln-CT language specifier, document new backends. check-in: 293badd94c user: mario tags: trunk | |
05:28 | support all 4 new Deep-Translate backends, still needs some rework to omit "auto" source language check-in: 7ad6ace92e user: mario tags: trunk | |
03:57 | Split out/optionalize version tool, note on Shift+F1 debugging check-in: 390c402fd5 user: mario tags: trunk | |
Changes
Changes to Addons.xcu.
︙ | ︙ | |||
727 728 729 730 731 732 733 | <prop oor:name="Context" oor:type="xs:string"><value/></prop> <prop oor:name="URL" oor:type="xs:string"><value>service:org.openoffice.comp.pyuno.pagetranslate?trigger&from=select&lang=select</value></prop> <prop oor:name="Title" oor:type="xs:string"><value/><value xml:lang="en-US">From ā To šŗ</value></prop> <prop oor:name="Target" oor:type="xs:string"><value>_self</value></prop> </node> <node oor:name="M5Z-CONFIG" oor:op="replace"> <prop oor:name="Context" oor:type="xs:string"><value/></prop> | | | 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 | <prop oor:name="Context" oor:type="xs:string"><value/></prop> <prop oor:name="URL" oor:type="xs:string"><value>service:org.openoffice.comp.pyuno.pagetranslate?trigger&from=select&lang=select</value></prop> <prop oor:name="Title" oor:type="xs:string"><value/><value xml:lang="en-US">From ā To šŗ</value></prop> <prop oor:name="Target" oor:type="xs:string"><value>_self</value></prop> </node> <node oor:name="M5Z-CONFIG" oor:op="replace"> <prop oor:name="Context" oor:type="xs:string"><value/></prop> <prop oor:name="URL" oor:type="xs:string"><value>.uno:OptionsTreeDialog?leaf=LanguageSettings?</value></prop> <prop oor:name="Title" oor:type="xs:string"><value/><value xml:lang="en-US">SettingsāLanguageā...</value></prop> <prop oor:name="Target" oor:type="xs:string"><value>_self</value></prop> </node> </node> </node> </node> </node> |
︙ | ︙ |
Changes to OptionsDialog.xdl.
1 2 3 4 5 6 7 8 9 | <?xml version="1.0" encoding="UTF-8"?> <!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"/> | | | | | | | | | | | | | 1 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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | <?xml version="1.0" encoding="UTF-8"?> <!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="12"> <dlg:menupopup> <dlg:menuitem dlg:value="Google Translate"/> <dlg:menuitem dlg:value="MyMemory"/> <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 (via Py-Trans)"/> <dlg:menuitem dlg:value="QCRI Machine Translation (via D-T)"/> <dlg:menuitem dlg:value="Yandex Translation (via D-T)"/> <dlg:menuitem dlg:value="Pons Dictionary (via D-T)"/> <dlg:menuitem dlg:value="Linguee Dictionary (via D-T)"/> </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&System=UNIX&UseDB=no" dlg:value="See on how the translation services 
"/> <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&System=UNIX&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&System=UNIX&UseDB=no" dlg:value="Some do require an additional Python extension. 
"/> <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&System=UNIX&UseDB=no" dlg:value="help pages"/> </dlg:bulletinboard> </dlg:window> |
Changes to description.xml.
1 2 3 | <?xml version="1.0" encoding="UTF-8"?> <description xmlns="http://openoffice.org/extensions/description/2006" xmlns:dep="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink"> <identifier value="vnd.include-once.pagetranslate"/> | | | 1 2 3 4 5 6 7 8 9 10 11 | <?xml version="1.0" encoding="UTF-8"?> <description xmlns="http://openoffice.org/extensions/description/2006" xmlns:dep="http://openoffice.org/extensions/description/2006" xmlns:xlink="http://www.w3.org/1999/xlink"> <identifier value="vnd.include-once.pagetranslate"/> <version value="1.7.4"/> <display-name> <name lang="en">PageTranslate</name> </display-name> <dependencies> <OpenOffice.org-minimal-version value="3.0" dep:name="OpenOffice.org 3.0"/> </dependencies> <registration> |
︙ | ︙ |
Changes to help/en/vnd.include-once.pagetranslate/config.xhp.
1 2 3 4 5 6 7 8 9 | <?xml version="1.0" encoding="UTF-8"?> <helpdocument version="1.0"> <meta> <topic id="topic_d1e3" indexer="include" status="PUBLISH"> <title xml-lang="en" id="title_d1e3">Translation settings</title> <filename>/help/vnd.include-once.pagetranslate/config.xhp</filename> </topic> <history> <created date="2020-02-02T22:22:22"/> | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?xml version="1.0" encoding="UTF-8"?> <helpdocument version="1.0"> <meta> <topic id="topic_d1e3" indexer="include" status="PUBLISH"> <title xml-lang="en" id="title_d1e3">Translation settings</title> <filename>/help/vnd.include-once.pagetranslate/config.xhp</filename> </topic> <history> <created date="2020-02-02T22:22:22"/> <lastedited date="2021-05-13T06:34:46.817+02:00"/> </history> </meta> <body> <bookmark id="bm_d1e7" branch="hid/vnd.include-once.pagetranslate:OptionsPageTranslate" xml-lang="en"> <bookmark_value>PageTranslate settings</bookmark_value> |
︙ | ︙ | |||
74 75 76 77 78 79 80 81 82 83 84 85 | <paragraph id="par_d1e101" role="paragraph" xml-lang="en">Allows to send each text paragraph to a local application. To use it, set the command in the according input field again. Placeholders are `{lang}` for the target language, and `{text}` for the paragaphs or current text section. (Both get automatically escaped). For <item type="command">translate-cli</item> you might need the <item type="variable">-p</item> provider option as well. See also the <link href="https://pypi.org/project/translate/">translate-python documentation</link> on how to prepare a separate <item type="fileitem">~/.python-translate.cfg</item>. </paragraph> </listitem> </list> </paragraph> | > > | | | | | | | | | | | | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | <paragraph id="par_d1e101" role="paragraph" xml-lang="en">Allows to send each text paragraph to a local application. To use it, set the command in the according input field again. Placeholders are `{lang}` for the target language, and `{text}` for the paragaphs or current text section. (Both get automatically escaped). For <item type="command">translate-cli</item> you might need the <item type="variable">-p</item> provider option as well. See also the <link href="https://pypi.org/project/translate/">translate-python documentation</link> on how to prepare a separate <item type="fileitem">~/.python-translate.cfg</item>. Or use <link href="https://github.com/nidhaloff/deep-translator">deep-translator cli</link> with for example <item type="command">deep_translator -trans "google" -src "auto" -tg {lang} -txt {text}</item>. </paragraph> </listitem> </list> </paragraph> <paragraph id="sect_d1e126" role="section" xml-lang="en"> <paragraph id="hd_d1e128" role="heading" level="2" xml-lang="en">Operation flags</paragraph> <list id="terms_d1e131" xml-lang="en"> <listitem id="item_d1e133" xml-lang="en"> <emph>ā quick linebreak handling</emph> <br/> <paragraph id="par_d1e138" role="paragraph" xml-lang="en">Might speed up table processing with Google Translate, as it avoids sending each newline-split sentence separately. It simply conjoins multiple lines temporarily with <item type="command">"/#Ā§/"</item> in place of a linebreak (and then rejoins them), so there are less requests. Primarily helps with tables, but less for documents with lengthy paragraphs.</paragraph> </listitem> <listitem id="item_d1e145" xml-lang="en"> <emph>ā also iterate over TextFrames</emph> <br/> <paragraph id="par_d1e150" role="paragraph" xml-lang="en">Handles normal and floating TextFrames. Those are essentially subdocuments in a Writer page. But you probably don't need this option for standard office documents.</paragraph> </listitem> <listitem id="item_d1e154" xml-lang="en"> <emph>ā super slow mode</emph> <br/> <paragraph id="par_d1e159" role="paragraph" xml-lang="en">Iterates over paragraph segments, to keep more inline formatting - but seriously harms mid-sentence translations. And currently the formatting still bleeds into adjoining paragraph segments, so not very useful in practice yet.</paragraph> </listitem> <listitem id="item_d1e163" xml-lang="en"> <emph>ā debug mode</emph> <br/> <paragraph id="par_d1e168" role="paragraph" xml-lang="en">Will fill up the <item type="fileitem">/tmp/pagetranslate-libreoffice.txt</item> log file quicker. Currently the debug mode is enabled by default anyway.</paragraph> </listitem> </list> </paragraph> </body> </helpdocument> |
Changes to help/en/vnd.include-once.pagetranslate/errors.duck.
︙ | ︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | Add an email address (ToolsāOptionsāLanguageāPageTranslate) for MyMemory. == MyMemory: 'AUTO' IS AN INVALID SOURCE LANGUAGE. This error shouldn't really happen anymore, as the default fallback for MyMemory is 'en' and not 'auto'. == How to report a bug [-- @link[seealso >>https://fossil.include-once.org/pagetranslate/] repository --] The project repository https://fossil.include-once.org/pagetranslate/ | > > > > > > | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | Add an email address (ToolsāOptionsāLanguageāPageTranslate) for MyMemory. == MyMemory: 'AUTO' IS AN INVALID SOURCE LANGUAGE. This error shouldn't really happen anymore, as the default fallback for MyMemory is 'en' and not 'auto'. == ImportError: No module named deep_translator You'll have to install this Python package first, before using some of the translation backends: `pip install deep-translator`. Or use a larger OXT with bundled extensions. == How to report a bug [-- @link[seealso >>https://fossil.include-once.org/pagetranslate/] repository --] The project repository https://fossil.include-once.org/pagetranslate/ |
︙ | ︙ |
Changes to help/en/vnd.include-once.pagetranslate/errors.xhp.
1 2 3 4 5 6 7 8 9 | <?xml version="1.0" encoding="UTF-8"?> <helpdocument version="1.0"> <meta> <topic id="topic_d1e1" indexer="include" status="PUBLISH"> <title xml-lang="en" id="title_d1e1">Errors</title> <filename>/help/vnd.include-once.pagetranslate/errors.xhp</filename> </topic> <history> <created date="2020-02-02T22:22:22"/> | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?xml version="1.0" encoding="UTF-8"?> <helpdocument version="1.0"> <meta> <topic id="topic_d1e1" indexer="include" status="PUBLISH"> <title xml-lang="en" id="title_d1e1">Errors</title> <filename>/help/vnd.include-once.pagetranslate/errors.xhp</filename> </topic> <history> <created date="2020-02-02T22:22:22"/> <lastedited date="2021-05-13T06:34:47.843+02:00"/> </history> </meta> <body> <link href="vnd.include-once.pagetranslate/index.xhp"/> <paragraph id="hd_d1e8" role="heading" level="1" xml-lang="en">Errors</paragraph> <paragraph id="par_d1e11" role="paragraph" xml-lang="en">Error messages will largely show up as long-winded popups with Python exceptions. Where the text usually starts with "Traceback" and then |
︙ | ︙ | |||
90 91 92 93 94 95 96 | </paragraph> <paragraph id="sect_d1e121" role="section" xml-lang="en"> <paragraph id="hd_d1e123" role="heading" level="2" xml-lang="en">MyMemory: 'AUTO' IS AN INVALID SOURCE LANGUAGE.</paragraph> <paragraph id="par_d1e126" role="paragraph" xml-lang="en">This error shouldn't really happen anymore, as the default fallback for MyMemory is 'en' and not 'auto'.</paragraph> </paragraph> <paragraph id="sect_d1e130" role="section" xml-lang="en"> | | > > > > > > | | | | | | | | | | | | 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | </paragraph> <paragraph id="sect_d1e121" role="section" xml-lang="en"> <paragraph id="hd_d1e123" role="heading" level="2" xml-lang="en">MyMemory: 'AUTO' IS AN INVALID SOURCE LANGUAGE.</paragraph> <paragraph id="par_d1e126" role="paragraph" xml-lang="en">This error shouldn't really happen anymore, as the default fallback for MyMemory is 'en' and not 'auto'.</paragraph> </paragraph> <paragraph id="sect_d1e130" role="section" xml-lang="en"> <paragraph id="hd_d1e132" role="heading" level="2" xml-lang="en">ImportError: No module named deep_translator</paragraph> <paragraph id="par_d1e135" role="paragraph" xml-lang="en">You'll have to install this Python package first, before using some of the translation backends: `pip install deep-translator`. Or use a larger OXT with bundled extensions.</paragraph> </paragraph> <paragraph id="sect_d1e139" role="section" xml-lang="en"> <paragraph id="hd_d1e141" role="heading" level="2" xml-lang="en">How to report a bug</paragraph> <paragraph id="par_d1e144" role="paragraph" xml-lang="en">The project repository https://fossil.include-once.org/pagetranslate/ allows to file a bug report (no registration necessary).</paragraph> <list id="list_d1e147" xml-lang="en"> <listitem id="item_d1e149" xml-lang="en"> <paragraph id="par_d1e151" role="paragraph" xml-lang="en">The log file MUST be included,</paragraph> </listitem> <listitem id="item_d1e155" xml-lang="en"> <paragraph id="par_d1e157" role="paragraph" xml-lang="en">together with a sample document (as link),</paragraph> </listitem> <listitem id="item_d1e161" xml-lang="en"> <paragraph id="par_d1e163" role="paragraph" xml-lang="en">as well as the OpenOffice version (Help ā About ā Copy)</paragraph> </listitem> <listitem id="item_d1e167" xml-lang="en"> <paragraph id="par_d1e169" role="paragraph" xml-lang="en">latest or development version has been tested.</paragraph> </listitem> </list> <paragraph id="par_d1e174" role="paragraph" xml-lang="en">Insufficient submissions are unlikely to spark developer interest.</paragraph> </paragraph> </body> </helpdocument> |
Changes to pagetranslate.py.
1 2 3 4 5 6 7 | #!/usr/bin/python # encoding: utf-8 # api: uno # type: callback # category: language # title: PageTranslate # description: Action button to get whole Writer document translated | | | 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.7.4 # state: beta # author: mario # url: https://fossil.include-once.org/pagetranslate/ # depends: python:requests (>= 2.5), python:uno # pack: *.py, pythonpath/*.py, META-INF/*, pkg-desc, *.x*, icons/* # license: GNU LGPL 2.1 # forked-from: TradutorLibreText (Claudemir de Almeida Rosa) |
︙ | ︙ |
Changes to pythonpath/pt_dialogs.py.
︙ | ︙ | |||
19 20 21 22 23 24 25 | from com.sun.star.task import XJobExecutor from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX from com.sun.star.awt import FontDescriptor | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from com.sun.star.task import XJobExecutor from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK, BUTTONS_OK_CANCEL, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_RETRY_CANCEL, BUTTONS_ABORT_IGNORE_RETRY from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_OK, DEFAULT_BUTTON_CANCEL, DEFAULT_BUTTON_RETRY, DEFAULT_BUTTON_YES, DEFAULT_BUTTON_NO, DEFAULT_BUTTON_IGNORE from com.sun.star.awt.MessageBoxType import MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX from com.sun.star.awt import FontDescriptor langs = ("auto", "acf", "af", "aig", "am", "ar", "az", "bah", "be", "bem", "bg", "bi", "bjs", "bn", "bod", "br", "bs", "ca", "cb", "cha", "cop", "crs", "cs", "cy", "da", "de", "div", "dzo", "el", "en", "eo", "es", "et", "eu", "fa", "fi", "fn", "fo", "fr", "ga", "gcl", "gd", "gl", "grc", "gu", "gv", "gyn", "ha", "haw", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "jam", "jv", "ka", "kab", "kal", "kea", "kk", "km", "kn", "ko", "ku", "ku", "ky", "la", "lb", "lo", "lt", "lv", "men", "mfe", "mg", "mh", "mi", "mk", "mn", "ms", "mt", "my", "ne", "niu", "nl", "no", "nso", "ny", "pa", "pap", "pau", "pis", "pl", "pot", "pov", "ppk", "ps", "pt", "qu", "rm", "ro", "ru", "run", "rw", "sg", "si", "sk", "sl", "smo", "sna", "so", "sq", "sr", "srn", "sv", "svc", "sw", "syc", "ta", "te", "tet", "tg", "th", "ti", "tk", "tkl", "tl", "tmh", "tn", "ton", "tpi", "tr", "tvl", "uk", "ur", "uz", "vi", "vic", "wls", "wo", "xh", "yi", "zdj", "zh-CN", "zh-TW", "zu") class ExcApp(unohelper.Base, XActionListener, XJobExecutor): """ Class documentation... """ def __init__(self, ctx=uno.getComponentContext(), err="error msg", exc="exception/traceback"): self.LocalContext = ctx |
︙ | ︙ |
Changes to pythonpath/translationbackends.py.
︙ | ︙ | |||
267 268 269 270 271 272 273 | return text def linebreakwise(self, text): return self.translate(text, preserve=1) # DeepL free API # | | | | | 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | return text def linebreakwise(self, text): return self.translate(text, preserve=1) # DeepL free API # # Registration is broken (error 10040 or whatever, "contact support" lel), even though # it seems to create an account regardless; but API yields SSL or connection errors. # Thus STILL UNTESTED. # class deepl_free_api(deepl_api): def __init__(self, params): self.params = params self.api_url = "http://api-free.deepl.com/v2/translate" |
︙ | ︙ | |||
328 329 330 331 332 333 334 | # Ā· more backends than pytranslate, # though PONS etc. are just dictionaries # ā https://github.com/nidhaloff/deep-translator # class deep_translator(google): def __init__(self, params={}): | < > > | | | > | > > > > > > > | | > > > | | 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 353 354 355 356 357 358 359 360 361 362 | # Ā· more backends than pytranslate, # though PONS etc. are just dictionaries # ā https://github.com/nidhaloff/deep-translator # class deep_translator(google): def __init__(self, params={}): self.params = params # config+argparse import deep_translator as dt import functools as ft w = params.get("backend", "Pons") if re.search("linguee", w, re.I): self.translate = self.from_words(dt.LingueeTranslator(source="auto", target=params["lang"]).translate) elif re.search("pons", w, re.I): self.translate = self.from_words(dt.PonsTranslator(source="auto", target=params["lang"]).translate) elif re.search("QCRI", w, re.I): self.translate = ft.partial(dt.QCRI(params["api_key"]).translate, source="auto", target=params["lang"]) elif re.search("yandex", w, re.I): self.translate = ft.partial(dt.YandexTranslator(params["api_key"]).translate, source="auto", target=params["lang"]) # decorator to translate word-wise def from_words(self, fn): def translate(text): words = re.findall("(\w+)", text) words = { w: fn(w) for w in list(set(words)) } text = re.sub("(\w+)", lambda m: words.get(m[0], m[0]), text) return text return translate translate = None #linebreakwise = None # MyMemory, only allows max 500 bytes input per API request. Therefore reusing # the Google backend, but with a different rx_split. |
︙ | ︙ | |||
456 457 458 459 460 461 462 | "^google": google, "^deepl [\s_] web": deepl_web, "^deepl [\s_] (api|pro)": deepl_api, "^deepl \s free": deepl_free_api, "^mymemory | translated\.net": mymemory, "^command | ^CLI | tool | program": cli, "^microsoft | translate[_-]py": translate_python, | | | | 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | "^google": google, "^deepl [\s_] web": deepl_web, "^deepl [\s_] (api|pro)": deepl_api, "^deepl \s free": deepl_free_api, "^mymemory | translated\.net": mymemory, "^command | ^CLI | tool | program": cli, "^microsoft | translate[_-]py": translate_python, "^linguee | ^pons | QCRI | yandex | deep-tr": deep_translator, } for rx, cls in map.items(): if re.search(rx, w, re.I|re.X): break else: cls = google return cls(params) |