--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/eric7/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/TranslationEngine.py Thu Jul 07 11:23:56 2022 +0200 @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2014 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the translation engine base class. +""" + +import contextlib + +from PyQt6.QtCore import pyqtSignal, QObject + + +class TranslationEngine(QObject): + """ + Class implementing the translation engine base class containing + default methods. + + @signal availableTranslationsLoaded() emitted to indicate the availability + of the list of supported translation languages + """ + availableTranslationsLoaded = pyqtSignal() + + def __init__(self, plugin, parent=None): + """ + Constructor + + @param plugin reference to the plugin object + @type TranslatorPlugin + @param parent reference to the parent object + @type QObject + """ + super().__init__(parent) + + self.plugin = plugin + + def engineName(self): + """ + Public method to get the name of the engine. + + @return engine name + @rtype str + """ + return "" + + def supportedLanguages(self): + """ + Public method to get the supported languages. + + @return list of supported language codes + @rtype list of str + """ + return [] + + def supportedTargetLanguages(self, original): + """ + Public method to get a list of supported target languages for an + original language. + + Note: The default implementation return the list of supported languages + (i.e. the same as those for the source) with the given original + removed. + + @param original original language + @type str + @return list of supported target languages for the given original + @rtype list of str + """ + targetLanguages = self.supportedLanguages()[:] + with contextlib.suppress(ValueError): + targetLanguages.remove(original) + + return targetLanguages + + def hasTTS(self): + """ + Public method indicating the Text-to-Speech capability. + + @return flag indicating the Text-to-Speech capability + @rtype bool + """ + return False + + def getTextToSpeechData(self, requestObject, text, language): + """ + Public method to pronounce the given text. + + @param requestObject reference to the request object + @type TranslatorRequest + @param text text to be pronounced + @type str + @param language language code of the text + @type str + @return tuple with pronounce data or an error string and a success flag + @rtype tuple of (QByteArray or str, bool) + """ + return self.tr("No pronounce data available"), False + + def getTranslation(self, requestObject, text, originalLanguage, + translationLanguage): + """ + Public method to translate the given text. + + @param requestObject reference to the request object + @type TranslatorRequest + @param text text to be translated + @type str + @param originalLanguage language code of the original + @type str + @param translationLanguage language code of the translation + @type str + @return tuple of translated text and flag indicating success + @rtype tuple of (str, bool) + """ + return self.tr("No translation available"), False