Added logic to load translations and to translate texts

This commit is contained in:
2022-06-29 20:03:13 +02:00
parent 39b6ca790c
commit e4f843829f
22 changed files with 204 additions and 30 deletions

View File

@@ -59,6 +59,17 @@ class ServiceCollection(ServiceCollectionABC):
for pipe in PipeABC.__subclasses__():
self.add_transient(PipeABC, pipe)
def add_translation(self):
try:
from cpl_translation.translation_service_abc import TranslationServiceABC
from cpl_translation.translation_service import TranslationService
from cpl_translation.translate_pipe import TranslatePipe
from cpl_translation.translation_settings import TranslationSettings
self.add_singleton(TranslationServiceABC, TranslationService)
self.add_transient(PipeABC, TranslatePipe)
except ImportError as e:
Console.error('cpl-translation is not installed', str(e))
def add_singleton(self, service_type: Union[type, object], service: Union[type, object] = None):
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
return self

View File

@@ -35,6 +35,11 @@ class ServiceCollectionABC(ABC):
r"""Adds the CPL internal pipes as transient"""
pass
@abstractmethod
def add_translation(self):
r"""Adds the CPL translation"""
pass
@abstractmethod
def add_transient(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
r"""Adds a service with transient lifetime