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

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9473
3f23dbf37dbe
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
14 14
15 class TranslationEngine(QObject): 15 class TranslationEngine(QObject):
16 """ 16 """
17 Class implementing the translation engine base class containing 17 Class implementing the translation engine base class containing
18 default methods. 18 default methods.
19 19
20 @signal availableTranslationsLoaded() emitted to indicate the availability 20 @signal availableTranslationsLoaded() emitted to indicate the availability
21 of the list of supported translation languages 21 of the list of supported translation languages
22 """ 22 """
23
23 availableTranslationsLoaded = pyqtSignal() 24 availableTranslationsLoaded = pyqtSignal()
24 25
25 def __init__(self, plugin, parent=None): 26 def __init__(self, plugin, parent=None):
26 """ 27 """
27 Constructor 28 Constructor
28 29
29 @param plugin reference to the plugin object 30 @param plugin reference to the plugin object
30 @type TranslatorPlugin 31 @type TranslatorPlugin
31 @param parent reference to the parent object 32 @param parent reference to the parent object
32 @type QObject 33 @type QObject
33 """ 34 """
34 super().__init__(parent) 35 super().__init__(parent)
35 36
36 self.plugin = plugin 37 self.plugin = plugin
37 38
38 def engineName(self): 39 def engineName(self):
39 """ 40 """
40 Public method to get the name of the engine. 41 Public method to get the name of the engine.
41 42
42 @return engine name 43 @return engine name
43 @rtype str 44 @rtype str
44 """ 45 """
45 return "" 46 return ""
46 47
47 def supportedLanguages(self): 48 def supportedLanguages(self):
48 """ 49 """
49 Public method to get the supported languages. 50 Public method to get the supported languages.
50 51
51 @return list of supported language codes 52 @return list of supported language codes
52 @rtype list of str 53 @rtype list of str
53 """ 54 """
54 return [] 55 return []
55 56
56 def supportedTargetLanguages(self, original): 57 def supportedTargetLanguages(self, original):
57 """ 58 """
58 Public method to get a list of supported target languages for an 59 Public method to get a list of supported target languages for an
59 original language. 60 original language.
60 61
61 Note: The default implementation return the list of supported languages 62 Note: The default implementation return the list of supported languages
62 (i.e. the same as those for the source) with the given original 63 (i.e. the same as those for the source) with the given original
63 removed. 64 removed.
64 65
65 @param original original language 66 @param original original language
66 @type str 67 @type str
67 @return list of supported target languages for the given original 68 @return list of supported target languages for the given original
68 @rtype list of str 69 @rtype list of str
69 """ 70 """
70 targetLanguages = self.supportedLanguages()[:] 71 targetLanguages = self.supportedLanguages()[:]
71 with contextlib.suppress(ValueError): 72 with contextlib.suppress(ValueError):
72 targetLanguages.remove(original) 73 targetLanguages.remove(original)
73 74
74 return targetLanguages 75 return targetLanguages
75 76
76 def hasTTS(self): 77 def hasTTS(self):
77 """ 78 """
78 Public method indicating the Text-to-Speech capability. 79 Public method indicating the Text-to-Speech capability.
79 80
80 @return flag indicating the Text-to-Speech capability 81 @return flag indicating the Text-to-Speech capability
81 @rtype bool 82 @rtype bool
82 """ 83 """
83 return False 84 return False
84 85
85 def getTextToSpeechData(self, requestObject, text, language): 86 def getTextToSpeechData(self, requestObject, text, language):
86 """ 87 """
87 Public method to pronounce the given text. 88 Public method to pronounce the given text.
88 89
89 @param requestObject reference to the request object 90 @param requestObject reference to the request object
90 @type TranslatorRequest 91 @type TranslatorRequest
91 @param text text to be pronounced 92 @param text text to be pronounced
92 @type str 93 @type str
93 @param language language code of the text 94 @param language language code of the text
94 @type str 95 @type str
95 @return tuple with pronounce data or an error string and a success flag 96 @return tuple with pronounce data or an error string and a success flag
96 @rtype tuple of (QByteArray or str, bool) 97 @rtype tuple of (QByteArray or str, bool)
97 """ 98 """
98 return self.tr("No pronounce data available"), False 99 return self.tr("No pronounce data available"), False
99 100
100 def getTranslation(self, requestObject, text, originalLanguage, 101 def getTranslation(
101 translationLanguage): 102 self, requestObject, text, originalLanguage, translationLanguage
103 ):
102 """ 104 """
103 Public method to translate the given text. 105 Public method to translate the given text.
104 106
105 @param requestObject reference to the request object 107 @param requestObject reference to the request object
106 @type TranslatorRequest 108 @type TranslatorRequest
107 @param text text to be translated 109 @param text text to be translated
108 @type str 110 @type str
109 @param originalLanguage language code of the original 111 @param originalLanguage language code of the original

eric ide

mercurial