18 |
18 |
19 |
19 |
20 def supportedEngineNames(): |
20 def supportedEngineNames(): |
21 """ |
21 """ |
22 Module function to get the list of supported translation engines. |
22 Module function to get the list of supported translation engines. |
23 |
23 |
24 @return names of supported engines |
24 @return names of supported engines |
25 @rtype list of str |
25 @rtype list of str |
26 """ |
26 """ |
27 return [ |
27 return [ |
28 "deepl", "googlev1", "googlev2", "ibm_watson", "microsoft", "mymemory", |
28 "deepl", |
|
29 "googlev1", |
|
30 "googlev2", |
|
31 "ibm_watson", |
|
32 "microsoft", |
|
33 "mymemory", |
29 "yandex", |
34 "yandex", |
30 ] |
35 ] |
31 |
36 |
32 |
37 |
33 def engineDisplayName(name): |
38 def engineDisplayName(name): |
34 """ |
39 """ |
35 Module function to get a translated name for an engine. |
40 Module function to get a translated name for an engine. |
36 |
41 |
37 @param name name of a translation engine |
42 @param name name of a translation engine |
38 @type str |
43 @type str |
39 @return translated engine name |
44 @return translated engine name |
40 @rtype str |
45 @rtype str |
41 """ |
46 """ |
42 return { |
47 return { |
43 "deepl": |
48 "deepl": QCoreApplication.translate("TranslatorEngines", "DeepL"), |
44 QCoreApplication.translate("TranslatorEngines", "DeepL"), |
49 "googlev1": QCoreApplication.translate("TranslatorEngines", "Google V.1"), |
45 "googlev1": |
50 "googlev2": QCoreApplication.translate("TranslatorEngines", "Google V.2"), |
46 QCoreApplication.translate("TranslatorEngines", "Google V.1"), |
51 "ibm_watson": QCoreApplication.translate("TranslatorEngines", "IBM Watson"), |
47 "googlev2": |
52 "microsoft": QCoreApplication.translate("TranslatorEngines", "Microsoft"), |
48 QCoreApplication.translate("TranslatorEngines", "Google V.2"), |
53 "mymemory": QCoreApplication.translate("TranslatorEngines", "MyMemory"), |
49 "ibm_watson": |
54 "yandex": QCoreApplication.translate("TranslatorEngines", "Yandex"), |
50 QCoreApplication.translate("TranslatorEngines", "IBM Watson"), |
|
51 "microsoft": |
|
52 QCoreApplication.translate("TranslatorEngines", "Microsoft"), |
|
53 "mymemory": |
|
54 QCoreApplication.translate("TranslatorEngines", "MyMemory"), |
|
55 "yandex": |
|
56 QCoreApplication.translate("TranslatorEngines", "Yandex"), |
|
57 }.get( |
55 }.get( |
58 name, |
56 name, |
59 QCoreApplication.translate( |
57 QCoreApplication.translate( |
60 "TranslatorEngines", "Unknow translation service name ({0})" |
58 "TranslatorEngines", "Unknow translation service name ({0})" |
61 ).format(name) |
59 ).format(name), |
62 ) |
60 ) |
63 |
61 |
64 |
62 |
65 def getTranslationEngine(name, plugin, parent=None): |
63 def getTranslationEngine(name, plugin, parent=None): |
66 """ |
64 """ |
67 Module function to instantiate an engine object for the named service. |
65 Module function to instantiate an engine object for the named service. |
68 |
66 |
69 @param name name of the online translation service |
67 @param name name of the online translation service |
70 @type str |
68 @type str |
71 @param plugin reference to the plugin object |
69 @param plugin reference to the plugin object |
72 @type TranslatorPlugin |
70 @type TranslatorPlugin |
73 @param parent reference to the parent object |
71 @param parent reference to the parent object |
75 @return translation engine |
73 @return translation engine |
76 @rtype TranslatorEngine |
74 @rtype TranslatorEngine |
77 """ |
75 """ |
78 if name == "deepl": |
76 if name == "deepl": |
79 from .DeepLEngine import DeepLEngine |
77 from .DeepLEngine import DeepLEngine |
|
78 |
80 engine = DeepLEngine(plugin, parent) |
79 engine = DeepLEngine(plugin, parent) |
81 elif name == "googlev1": |
80 elif name == "googlev1": |
82 from .GoogleV1Engine import GoogleV1Engine |
81 from .GoogleV1Engine import GoogleV1Engine |
|
82 |
83 engine = GoogleV1Engine(plugin, parent) |
83 engine = GoogleV1Engine(plugin, parent) |
84 elif name == "googlev2": |
84 elif name == "googlev2": |
85 from .GoogleV2Engine import GoogleV2Engine |
85 from .GoogleV2Engine import GoogleV2Engine |
|
86 |
86 engine = GoogleV2Engine(plugin, parent) |
87 engine = GoogleV2Engine(plugin, parent) |
87 elif name == "ibm_watson": |
88 elif name == "ibm_watson": |
88 from .IbmWatsonEngine import IbmWatsonEngine |
89 from .IbmWatsonEngine import IbmWatsonEngine |
|
90 |
89 engine = IbmWatsonEngine(plugin, parent) |
91 engine = IbmWatsonEngine(plugin, parent) |
90 elif name == "microsoft": |
92 elif name == "microsoft": |
91 from .MicrosoftEngine import MicrosoftEngine |
93 from .MicrosoftEngine import MicrosoftEngine |
|
94 |
92 engine = MicrosoftEngine(plugin, parent) |
95 engine = MicrosoftEngine(plugin, parent) |
93 elif name == "mymemory": |
96 elif name == "mymemory": |
94 from .MyMemoryEngine import MyMemoryEngine |
97 from .MyMemoryEngine import MyMemoryEngine |
|
98 |
95 engine = MyMemoryEngine(plugin, parent) |
99 engine = MyMemoryEngine(plugin, parent) |
96 elif name == "yandex": |
100 elif name == "yandex": |
97 from .YandexEngine import YandexEngine |
101 from .YandexEngine import YandexEngine |
|
102 |
98 engine = YandexEngine(plugin, parent) |
103 engine = YandexEngine(plugin, parent) |
99 else: |
104 else: |
100 engine = None |
105 engine = None |
101 return engine |
106 return engine |
102 |
107 |
103 |
108 |
104 def getEngineIcon(name): |
109 def getEngineIcon(name): |
105 """ |
110 """ |
106 Module function to get the icon of the named engine. |
111 Module function to get the icon of the named engine. |
107 |
112 |
108 @param name name of the translation engine |
113 @param name name of the translation engine |
109 @type str |
114 @type str |
110 @return engine icon |
115 @return engine icon |
111 @rtype QIcon |
116 @rtype QIcon |
112 """ |
117 """ |
113 iconSuffix = "dark" if ericApp().usesDarkPalette() else "light" |
118 iconSuffix = "dark" if ericApp().usesDarkPalette() else "light" |
114 if name in supportedEngineNames(): |
119 if name in supportedEngineNames(): |
115 icon = UI.PixmapCache.getIcon(os.path.join( |
120 icon = UI.PixmapCache.getIcon( |
116 os.path.dirname(__file__), "..", "icons", "engines", |
121 os.path.join( |
117 "{0}-{1}".format(name, iconSuffix))) |
122 os.path.dirname(__file__), |
|
123 "..", |
|
124 "icons", |
|
125 "engines", |
|
126 "{0}-{1}".format(name, iconSuffix), |
|
127 ) |
|
128 ) |
118 if icon.isNull(): |
129 if icon.isNull(): |
119 # try variant without suffix |
130 # try variant without suffix |
120 icon = UI.PixmapCache.getIcon(os.path.join( |
131 icon = UI.PixmapCache.getIcon( |
121 os.path.dirname(__file__), "..", "icons", "engines", |
132 os.path.join( |
122 "{0}".format(name))) |
133 os.path.dirname(__file__), |
|
134 "..", |
|
135 "icons", |
|
136 "engines", |
|
137 "{0}".format(name), |
|
138 ) |
|
139 ) |
123 return icon |
140 return icon |
124 else: |
141 else: |
125 return QIcon() |
142 return QIcon() |
126 |
143 |
127 |
144 |
128 def getKeyUrl(name): |
145 def getKeyUrl(name): |
129 """ |
146 """ |
130 Module function to get an URL to request a user key. |
147 Module function to get an URL to request a user key. |
131 |
148 |
132 @param name name of the online translation service |
149 @param name name of the online translation service |
133 @type str |
150 @type str |
134 @return key request URL |
151 @return key request URL |
135 @rtype str |
152 @rtype str |
136 """ |
153 """ |
137 return { |
154 return { |
138 "deepl": |
155 "deepl": "https://www.deepl.com/de/pro-api", |
139 "https://www.deepl.com/de/pro-api", |
156 "googlev2": "https://console.developers.google.com/", |
140 "googlev2": |
157 "ibm_watson": "https://www.ibm.com/watson/services/language-translator/", |
141 "https://console.developers.google.com/", |
158 "microsoft": "https://portal.azure.com", |
142 "ibm_watson": |
159 "mymemory": "http://mymemory.translated.net/doc/keygen.php", |
143 "https://www.ibm.com/watson/services/language-translator/", |
160 "yandex": "http://api.yandex.com/key/form.xml?service=trnsl", |
144 "microsoft": |
|
145 "https://portal.azure.com", |
|
146 "mymemory": |
|
147 "http://mymemory.translated.net/doc/keygen.php", |
|
148 "yandex": |
|
149 "http://api.yandex.com/key/form.xml?service=trnsl", |
|
150 }.get(name, "") |
161 }.get(name, "") |