src/eric7/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/__init__.py

Sat, 23 Dec 2023 15:48:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 15:48:12 +0100
branch
eric7
changeset 10439
21c28b0f9e41
parent 9956
5b138f996a1e
child 11090
f5f5f5803935
permissions
-rw-r--r--

Updated copyright for 2024.

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
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9956
diff changeset
3 # Copyright (c) 2014 - 2024 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
9495
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
10 import contextlib
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
11 import importlib
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 import os
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
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
14 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
15 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
16
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
17 from eric7.EricGui import EricPixmapCache
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
18 from eric7.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
19
9774
c7b712056146 Added a TODO marker to add an interface to the 'Libre Translate' engine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
20
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def supportedEngineNames():
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Module function to get the list of supported translation engines.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
24
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
25 @return names of supported engines
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
26 @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
27 """
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
28 return [
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29 "deepl",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
30 "googlev1",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
31 "googlev2",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
32 "ibm_watson",
9956
5b138f996a1e Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
33 "libre_translate",
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34 "microsoft",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35 "mymemory",
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
36 "yandex",
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
37 ]
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 def engineDisplayName(name):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 Module function to get a translated name for an engine.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
44 @param name name of a translation engine
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
45 @type str
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
46 @return translated engine name
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
47 @rtype str
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 """
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
49 return {
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50 "deepl": QCoreApplication.translate("TranslatorEngines", "DeepL"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51 "googlev1": QCoreApplication.translate("TranslatorEngines", "Google V.1"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52 "googlev2": QCoreApplication.translate("TranslatorEngines", "Google V.2"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53 "ibm_watson": QCoreApplication.translate("TranslatorEngines", "IBM Watson"),
9956
5b138f996a1e Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
54 "libre_translate": QCoreApplication.translate(
5b138f996a1e Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
55 "TranslatorEngines", "LibreTranslate"
5b138f996a1e Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
56 ),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57 "microsoft": QCoreApplication.translate("TranslatorEngines", "Microsoft"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 "mymemory": QCoreApplication.translate("TranslatorEngines", "MyMemory"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 "yandex": QCoreApplication.translate("TranslatorEngines", "Yandex"),
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
60 }.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
61 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
62 QCoreApplication.translate(
7256
4ef3b78ebb4e Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
63 "TranslatorEngines", "Unknow translation service name ({0})"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
64 ).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
65 )
6018
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
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 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
69 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Module function to instantiate an engine object for the named service.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
71
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
72 @param name name of the online translation service
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
73 @type str
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
74 @param plugin reference to the plugin object
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
75 @type TranslatorPlugin
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @param parent reference to the parent object
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
77 @type QObject
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
78 @return translation engine
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
79 @rtype TranslatorEngine
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
9495
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
81 engineMapping = {
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
82 "deepl": ".DeepLEngine",
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
83 "googlev1": ".GoogleV1Engine",
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
84 "googlev2": ".GoogleV2Engine",
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
85 "ibm_watson": ".IbmWatsonEngine",
9956
5b138f996a1e Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9786
diff changeset
86 "libre_translate": ".LibreTranslateEngine",
9495
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
87 "microsoft": ".MicrosoftEngine",
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
88 "mymemory": ".MyMemoryEngine",
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
89 "yandex": ".YandexEngine",
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
90 }
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91
9495
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
92 with contextlib.suppress(KeyError):
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
93 mod = importlib.import_module(engineMapping[name], __package__)
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
94 if mod:
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
95 return mod.createEngine(plugin, parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
96
9495
28ab5f487f71 Changed translation engine imports to use importlib.import_module().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9482
diff changeset
97 return None
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 def getEngineIcon(name):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 Module function to get the icon of the named engine.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 @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
105 @type str
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 @return engine icon
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 @rtype QIcon
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 """
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
109 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
110 if name in supportedEngineNames():
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
111 icon = EricPixmapCache.getIcon(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
112 os.path.join(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
113 os.path.dirname(__file__),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
114 "..",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115 "icons",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
116 "engines",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117 "{0}-{1}".format(name, iconSuffix),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
118 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
119 )
7505
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
120 if icon.isNull():
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
121 # try variant without suffix
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
122 icon = EricPixmapCache.getIcon(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
123 os.path.join(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
124 os.path.dirname(__file__),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
125 "..",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
126 "icons",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
127 "engines",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
128 "{0}".format(name),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
129 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130 )
7505
7d3cfeeb5f4f Added breeze style icons for the Translator plug-in.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
131 return icon
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 else:
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 return QIcon()
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 def getKeyUrl(name):
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 """
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 Module function to get an URL to request a user key.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
139
9148
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
140 @param name name of the online translation service
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
141 @type str
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
142 @return key request URL
b31f0d894b55 Translator
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9145
diff changeset
143 @rtype str
6018
1c858879d3d0 Added the translator plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 """
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
145 return {
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146 "deepl": "https://www.deepl.com/de/pro-api",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
147 "googlev2": "https://console.developers.google.com/",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148 "ibm_watson": "https://www.ibm.com/watson/services/language-translator/",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
149 "microsoft": "https://portal.azure.com",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150 "mymemory": "http://mymemory.translated.net/doc/keygen.php",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
151 "yandex": "http://api.yandex.com/key/form.xml?service=trnsl",
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
152 }.get(name, "")

eric ide

mercurial