Pluggability of Transaltion service
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.
Integration
Translation service is used for supporting multiple languages in Sakhi-api-service.
BaseTranslationClass
This BaseTranslationClass
class has below methods which are to be implemented mandatorily.
Implementation
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.
Last updated