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

changeset 7748
23e98236a4c4
parent 7360
9190402e4505
child 7780
41420f82c0ac
equal deleted inserted replaced
7747:4f0b034f4c34 7748:23e98236a4c4
68 @param translationLanguage language code of the translation (string) 68 @param translationLanguage language code of the translation (string)
69 @return tuple of translated text (string) and flag indicating 69 @return tuple of translated text (string) and flag indicating
70 success (boolean) 70 success (boolean)
71 """ 71 """
72 if len(text) > self.MaxTranslationTextLen: 72 if len(text) > self.MaxTranslationTextLen:
73 return self.tr( 73 return (
74 "Text to be translated exceeds the translation limit of {0}" 74 self.tr("DeepL: Text to be translated exceeds the translation"
75 " characters.").format(self.MaxTranslationTextLen), False 75 " limit of {0} characters.")
76 .format(self.MaxTranslationTextLen),
77 False
78 )
76 79
77 apiKey = self.plugin.getPreferences("DeeplKey") 80 apiKey = self.plugin.getPreferences("DeeplKey")
78 if not apiKey: 81 if not apiKey:
79 return self.tr("A valid DeepL Pro key is required."), False 82 return self.tr("A valid DeepL Pro key is required."), False
80 83
97 if "translations" not in responseDict: 100 if "translations" not in responseDict:
98 return self.tr("DeepL call returned an unknown result"), False 101 return self.tr("DeepL call returned an unknown result"), False
99 102
100 translations = responseDict["translations"] 103 translations = responseDict["translations"]
101 if len(translations) == 0: 104 if len(translations) == 0:
102 return self.tr("<p>No translation found</p>"), True 105 return self.tr("<p>DeepL: No translation found</p>"), True
103 106
104 # show sentence by sentence separated by a line 107 # show sentence by sentence separated by a line
105 result = ( 108 result = (
106 "<p>" + 109 "<p>" +
107 "<hr/>".join([t["text"] for t in translations]) + 110 "<hr/>".join([t["text"] for t in translations]) +

eric ide

mercurial