Thu, 07 Jul 2022 11:23:56 +0200
Reorganized the project structure to use the source layout in order to support up-to-date build systems with "pyproject.toml".
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
3 | # Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Package containing the various translation engines. |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | import os |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | |
8318
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
12 | from PyQt6.QtCore import QCoreApplication |
962bce857696
Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
13 | from PyQt6.QtGui import QIcon |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
8358
144a6b854f70
Sorted the eric specific extensions into packages named like the corresponding PyQt packages (i.e. EricCore,EricGui and EricWidgets).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8356
diff
changeset
|
15 | from EricWidgets.EricApplication import ericApp |
7505
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
16 | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | import UI.PixmapCache |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | def supportedEngineNames(): |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | Module function to get the list of supported translation engines. |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | |
9148 | 24 | @return names of supported engines |
25 | @rtype list of str | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | """ |
9148 | 27 | return [ |
28 | "deepl", "googlev1", "googlev2", "ibm_watson", "microsoft", "mymemory", | |
29 | "yandex", | |
30 | ] | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
32 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | def engineDisplayName(name): |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | Module function to get a translated name for an engine. |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | |
9148 | 37 | @param name name of a translation engine |
38 | @type str | |
39 | @return translated engine name | |
40 | @rtype str | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | """ |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
42 | return { |
9148 | 43 | "deepl": |
44 | QCoreApplication.translate("TranslatorEngines", "DeepL"), | |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
45 | "googlev1": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
46 | QCoreApplication.translate("TranslatorEngines", "Google V.1"), |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
47 | "googlev2": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
48 | QCoreApplication.translate("TranslatorEngines", "Google V.2"), |
9148 | 49 | "ibm_watson": |
50 | QCoreApplication.translate("TranslatorEngines", "IBM Watson"), | |
51 | "microsoft": | |
52 | QCoreApplication.translate("TranslatorEngines", "Microsoft"), | |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
53 | "mymemory": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
54 | QCoreApplication.translate("TranslatorEngines", "MyMemory"), |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
55 | "yandex": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
56 | QCoreApplication.translate("TranslatorEngines", "Yandex"), |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
57 | }.get( |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
58 | name, |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
59 | QCoreApplication.translate( |
7256
4ef3b78ebb4e
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
60 | "TranslatorEngines", "Unknow translation service name ({0})" |
4ef3b78ebb4e
Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7229
diff
changeset
|
61 | ).format(name) |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
62 | ) |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
63 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
64 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | def getTranslationEngine(name, plugin, parent=None): |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | Module function to instantiate an engine object for the named service. |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
9148 | 69 | @param name name of the online translation service |
70 | @type str | |
71 | @param plugin reference to the plugin object | |
72 | @type TranslatorPlugin | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
73 | @param parent reference to the parent object |
9148 | 74 | @type QObject |
75 | @return translation engine | |
76 | @rtype TranslatorEngine | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
77 | """ |
9148 | 78 | if name == "deepl": |
79 | from .DeepLEngine import DeepLEngine | |
80 | engine = DeepLEngine(plugin, parent) | |
81 | elif name == "googlev1": | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | from .GoogleV1Engine import GoogleV1Engine |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | engine = GoogleV1Engine(plugin, parent) |
9148 | 84 | elif name == "googlev2": |
85 | from .GoogleV2Engine import GoogleV2Engine | |
86 | engine = GoogleV2Engine(plugin, parent) | |
87 | elif name == "ibm_watson": | |
88 | from .IbmWatsonEngine import IbmWatsonEngine | |
89 | engine = IbmWatsonEngine(plugin, parent) | |
90 | elif name == "microsoft": | |
91 | from .MicrosoftEngine import MicrosoftEngine | |
92 | engine = MicrosoftEngine(plugin, parent) | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | elif name == "mymemory": |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | from .MyMemoryEngine import MyMemoryEngine |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | engine = MyMemoryEngine(plugin, parent) |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | elif name == "yandex": |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | from .YandexEngine import YandexEngine |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | engine = YandexEngine(plugin, parent) |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | else: |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | engine = None |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | return engine |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | def getEngineIcon(name): |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | Module function to get the icon of the named engine. |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | @param name name of the translation engine |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | @type str |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | @return engine icon |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | @rtype QIcon |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | """ |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
113 | iconSuffix = "dark" if ericApp().usesDarkPalette() else "light" |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | if name in supportedEngineNames(): |
7505
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
115 | icon = UI.PixmapCache.getIcon(os.path.join( |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | os.path.dirname(__file__), "..", "icons", "engines", |
7505
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
117 | "{0}-{1}".format(name, iconSuffix))) |
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
118 | if icon.isNull(): |
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
119 | # try variant without suffix |
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
120 | icon = UI.PixmapCache.getIcon(os.path.join( |
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
121 | os.path.dirname(__file__), "..", "icons", "engines", |
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
122 | "{0}".format(name))) |
7d3cfeeb5f4f
Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7360
diff
changeset
|
123 | return icon |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | else: |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | return QIcon() |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | def getKeyUrl(name): |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | """ |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | Module function to get an URL to request a user key. |
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | |
9148 | 132 | @param name name of the online translation service |
133 | @type str | |
134 | @return key request URL | |
135 | @rtype str | |
6018
1c858879d3d0
Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | """ |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
137 | return { |
9148 | 138 | "deepl": |
139 | "https://www.deepl.com/de/pro-api", | |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
140 | "googlev2": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
141 | "https://console.developers.google.com/", |
9148 | 142 | "ibm_watson": |
143 | "https://www.ibm.com/watson/services/language-translator/", | |
144 | "microsoft": | |
145 | "https://portal.azure.com", | |
8237
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
146 | "mymemory": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
147 | "http://mymemory.translated.net/doc/keygen.php", |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
148 | "yandex": |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
149 | "http://api.yandex.com/key/form.xml?service=trnsl", |
acc1490f822e
Applied some more code simplifications suggested by the new Simplify checker (Y116: use dictionary access instead of multiple ifs).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8234
diff
changeset
|
150 | }.get(name, "") |