|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the translation engine base class. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSignal, QObject |
|
13 |
|
14 |
|
15 class TranslationEngine(QObject): |
|
16 """ |
|
17 Class implementing the translation engine base class containing |
|
18 default methods. |
|
19 |
|
20 @signal availableTranslationsLoaded() emitted to indicate the availability |
|
21 of the list of supported translation languages |
|
22 """ |
|
23 availableTranslationsLoaded = pyqtSignal() |
|
24 |
|
25 def __init__(self, plugin, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param plugin reference to the plugin object (TranslatorPlugin) |
|
30 @param parent reference to the parent object (QObject) |
|
31 """ |
|
32 super(TranslationEngine, self).__init__(parent) |
|
33 |
|
34 self.plugin = plugin |
|
35 |
|
36 def engineName(self): |
|
37 """ |
|
38 Public method to get the name of the engine. |
|
39 |
|
40 @return engine name (string) |
|
41 """ |
|
42 return "" |
|
43 |
|
44 def supportedLanguages(self): |
|
45 """ |
|
46 Public method to get the supported languages. |
|
47 |
|
48 @return list of supported language codes (list of string) |
|
49 """ |
|
50 return [] |
|
51 |
|
52 def supportedTargetLanguages(self, original): |
|
53 """ |
|
54 Public method to get a list of supported target languages for an |
|
55 original language. |
|
56 |
|
57 Note: The default implementation return the list of supported languages |
|
58 (i.e. the same as those for the source) with the given original |
|
59 removed. |
|
60 |
|
61 @param original original language |
|
62 @type str |
|
63 @return list of supported target languages for the given original |
|
64 @rtype list of str |
|
65 """ |
|
66 targetLanguages = self.supportedLanguages()[:] |
|
67 try: |
|
68 targetLanguages.remove(original) |
|
69 except ValueError: |
|
70 # original is not in the list of target languages |
|
71 pass |
|
72 |
|
73 return targetLanguages |
|
74 |
|
75 def hasTTS(self): |
|
76 """ |
|
77 Public method indicating the Text-to-Speech capability. |
|
78 |
|
79 @return flag indicating the Text-to-Speech capability (boolean) |
|
80 """ |
|
81 return False |
|
82 |
|
83 def getTextToSpeechData(self, requestObject, text, language): |
|
84 """ |
|
85 Public method to pronounce the given text. |
|
86 |
|
87 @param requestObject reference to the request object |
|
88 (TranslatorRequest) |
|
89 @param text text to be pronounced (string) |
|
90 @param language language code of the text (string) |
|
91 @return tuple with pronounce data (QByteArray) or error string (string) |
|
92 and success flag (boolean) |
|
93 """ |
|
94 return self.tr("No pronounce data available"), False |
|
95 |
|
96 def getTranslation(self, requestObject, text, originalLanguage, |
|
97 translationLanguage): |
|
98 """ |
|
99 Public method to translate the given text. |
|
100 |
|
101 @param requestObject reference to the request object |
|
102 (TranslatorRequest) |
|
103 @param text text to be translated (string) |
|
104 @param originalLanguage language code of the original (string) |
|
105 @param translationLanguage language code of the translation (string) |
|
106 @return tuple of translated text (string) and flag indicating |
|
107 success (boolean) |
|
108 """ |
|
109 return self.tr("No translation available"), False |