Pluggability of Transaltion service
Last updated
Last updated
In this guide, we will learn how to plugin a new translation service by extending the BaseTranslationClass
interface.
You can seamlessly leverage it within existing Sakhi API workflows with minimal code changes.
Translation service is used for supporting multiple languages in Sakhi-api-service.
This BaseTranslationClass
class has below methods which are to be implemented mandatorily.
Method/Property | Description | Required/Optional |
---|---|---|
Let's say we create a YourTranslationClass
class inheriting from BaseTranslationClass.
The class needs to implement the following methods translate_text, text_to_speech and speech_to_text.
Add the necessary environment variables to .env
file. TRANSLATION_TYPE
is to be defined mandatorily.
Now go to the 'translation' folder and create your plugin 'your_translation_service.py
'. Provide the implementation for the abstract methods.
Go to the 'translation' folder and update __init__.py
with the module lookup entry for "YourTranslationClass" and also for TYPE_CHECKING.
Modify env_manager.py
to import YourTranslationClass
and add a mapping for YourTranslationClass
in the self.indexes
dictionary.
This setup ensures that YourTranslationClass can be instantiated based on specific environment variables, effectively integrating it into the environment management system. The self.indexes
the dictionary now includes a mapping where "your_translation_service"
corresponds to the "YourTranslationClass"
class and uses "TRANSLATION_TYPE"
as the environment key.
__init__
Method to initialise or define necessary variables
Optional
translate_text
This method translates a text string to another language.
Required
text_to_speech
This method converts text to speech in a specified language.
Required
speech_to_text
This method converts speech from an audio file to text.
Required