eric7/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/DeepLEngine.py

branch
eric7
changeset 9145
520a70c5437f
parent 8881
54e42bc2437a
child 9148
b31f0d894b55
--- a/eric7/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/DeepLEngine.py	Fri Jun 10 18:13:47 2022 +0200
+++ b/eric7/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/DeepLEngine.py	Sun Jun 12 15:48:24 2022 +0200
@@ -21,7 +21,10 @@
     Class implementing the translation engine for the DeepL
     translation service.
     """
-    TranslatorUrl = "https://api.deepl.com/v1/translate"
+    TranslatorUrls = {
+        "pro": "https://api.deepl.com/v2/translate",
+        "free": "https://api-free.deepl.com/v2/translate",
+    }
     MaxTranslationTextLen = 30 * 1024
     
     def __init__(self, plugin, parent=None):
@@ -53,7 +56,9 @@
         @return list of supported language codes
         @rtype list of str
         """
-        return ["de", "en", "es", "fr", "it", "nl", "pl", ]
+        return ["bg", "cs", "da", "de", "el", "en", "es", "et", "fi", "fr",
+                "hu", "id", "it", "ja", "lt", "lv", "nl", "pl", "pt", "ro",
+                "ru", "sk", "sl", "sv", "tr", "zh"]
     
     def getTranslation(self, requestObject, text, originalLanguage,
                        translationLanguage):
@@ -89,7 +94,12 @@
             .toPercentEncoding()
         )
         request = params + encodedText
-        response, ok = requestObject.post(QUrl(self.TranslatorUrl), request)
+        translatorUrl = (
+            DeepLEngine.TranslatorUrls["free"]
+            if apiKey.endswith(":fx") else
+            DeepLEngine.TranslatorUrls["pro"]
+        )
+        response, ok = requestObject.post(QUrl(translatorUrl), request)
         if ok:
             try:
                 responseDict = json.loads(response)

eric ide

mercurial