Compare commits
3 Commits
6d75bc433e
...
e4f843829f
Author | SHA1 | Date | |
---|---|---|---|
e4f843829f | |||
39b6ca790c | |||
4c8d7a8031 |
@ -11,24 +11,20 @@
|
|||||||
"unittests_cli": "unittests/unittests_cli/unittests_cli.json",
|
"unittests_cli": "unittests/unittests_cli/unittests_cli.json",
|
||||||
"unittests_core": "unittests/unittests_core/unittests_core.json",
|
"unittests_core": "unittests/unittests_core/unittests_core.json",
|
||||||
"unittests_query": "unittests/unittests_query/unittests_query.json",
|
"unittests_query": "unittests/unittests_query/unittests_query.json",
|
||||||
"unittests_shared": "unittests/unittests_shared/unittests_shared.json"
|
"unittests_shared": "unittests/unittests_shared/unittests_shared.json",
|
||||||
|
"cpl-translation": "src/cpl_translation/cpl-translation.json"
|
||||||
},
|
},
|
||||||
"Scripts": {
|
"Scripts": {
|
||||||
"hello-world": "echo 'Hello World'",
|
"hello-world": "echo 'Hello World'",
|
||||||
|
|
||||||
"sv": "cpl set-version",
|
"sv": "cpl set-version",
|
||||||
"set-version": "cpl run set-version $ARGS; echo '';",
|
"set-version": "cpl run set-version $ARGS; echo '';",
|
||||||
|
|
||||||
"spu": "cpl set-pip-urls",
|
"spu": "cpl set-pip-urls",
|
||||||
"set-pip-urls": "cpl run set-pip-urls $ARGS; echo '';",
|
"set-pip-urls": "cpl run set-pip-urls $ARGS; echo '';",
|
||||||
|
|
||||||
"docs-build": "echo 'Build Documentation'; cd docs/; sphinx-apidoc -o source/ ../src/cpl_core; sphinx-apidoc -o source/ ../src/cpl_query; make clean; make html; rm source/cpl_query.tests.rst;",
|
"docs-build": "echo 'Build Documentation'; cd docs/; sphinx-apidoc -o source/ ../src/cpl_core; sphinx-apidoc -o source/ ../src/cpl_query; make clean; make html; rm source/cpl_query.tests.rst;",
|
||||||
"db": "cpl docs-build",
|
"db": "cpl docs-build",
|
||||||
"docs-open": "xdg-open $PWD/docs/build/html/index.html &",
|
"docs-open": "xdg-open $PWD/docs/build/html/index.html &",
|
||||||
"do": "cpl docs-open",
|
"do": "cpl docs-open",
|
||||||
|
|
||||||
"test": "cpl run unittests",
|
"test": "cpl run unittests",
|
||||||
|
|
||||||
"pre-build-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
"pre-build-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
||||||
"build-all": "cpl build-cli; cpl build-core; cpl build-query; cpl build-set-pip-urls; cpl build-set-version",
|
"build-all": "cpl build-cli; cpl build-core; cpl build-query; cpl build-set-pip-urls; cpl build-set-version",
|
||||||
"ba": "cpl build-all $ARGS",
|
"ba": "cpl build-all $ARGS",
|
||||||
@ -37,14 +33,12 @@
|
|||||||
"build-query": "echo 'Build cpl-query'; cd ./src/cpl_query; cpl build; cd ../../;",
|
"build-query": "echo 'Build cpl-query'; cd ./src/cpl_query; cpl build; cd ../../;",
|
||||||
"build-set-pip-urls": "echo 'Build set-pip-urls'; cd ./tools/set_pip_urls; cpl build; cd ../../;",
|
"build-set-pip-urls": "echo 'Build set-pip-urls'; cd ./tools/set_pip_urls; cpl build; cd ../../;",
|
||||||
"build-set-version": "echo 'Build set-version'; cd ./tools/set_version; cpl build; cd ../../;",
|
"build-set-version": "echo 'Build set-version'; cd ./tools/set_version; cpl build; cd ../../;",
|
||||||
|
|
||||||
"pre-publish-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
"pre-publish-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
||||||
"publish-all": "cpl publish-cli; cpl publish-core; cpl publish-query;",
|
"publish-all": "cpl publish-cli; cpl publish-core; cpl publish-query;",
|
||||||
"pa": "cpl build-all $ARGS",
|
"pa": "cpl build-all $ARGS",
|
||||||
"publish-cli": "echo 'Publish cpl-cli'; cd ./src/cpl_cli; cpl publish; cd ../../;",
|
"publish-cli": "echo 'Publish cpl-cli'; cd ./src/cpl_cli; cpl publish; cd ../../;",
|
||||||
"publish-core": "echo 'Publish cpl-core'; cd ./src/cpl_core; cpl publish; cd ../../;",
|
"publish-core": "echo 'Publish cpl-core'; cd ./src/cpl_core; cpl publish; cd ../../;",
|
||||||
"publish-query": "echo 'Publish cpl_query'; cd ./src/cpl_query; cpl publish; cd ../../;",
|
"publish-query": "echo 'Publish cpl_query'; cd ./src/cpl_query; cpl publish; cd ../../;",
|
||||||
|
|
||||||
"upload-prod-cli": "echo 'PROD Upload cpl-cli'; cpl upl-prod-cli;",
|
"upload-prod-cli": "echo 'PROD Upload cpl-cli'; cpl upl-prod-cli;",
|
||||||
"upl-prod-cli": "twine upload -r pip.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
"upl-prod-cli": "twine upload -r pip.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||||
"upload-prod-core": "echo 'PROD Upload cpl-core'; cpl upl-prod-core;",
|
"upload-prod-core": "echo 'PROD Upload cpl-core'; cpl upl-prod-core;",
|
||||||
@ -63,28 +57,24 @@
|
|||||||
"upl-dev-core": "twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*",
|
"upl-dev-core": "twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||||
"upload-dev-query": "echo 'DEV Upload cpl_query'; cpl upl-dev-query;",
|
"upload-dev-query": "echo 'DEV Upload cpl_query'; cpl upl-dev-query;",
|
||||||
"upl-dev-query": "twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*",
|
"upl-dev-query": "twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||||
|
|
||||||
"pre-deploy-prod": "cpl sv $ARGS; cpl spu --environment=production;",
|
"pre-deploy-prod": "cpl sv $ARGS; cpl spu --environment=production;",
|
||||||
"deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-query;",
|
"deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-query;",
|
||||||
"dp": "cpl deploy-prod $ARGS",
|
"dp": "cpl deploy-prod $ARGS",
|
||||||
"deploy-prod-cli": "cpl publish-cli; cpl upload-prod-cli",
|
"deploy-prod-cli": "cpl publish-cli; cpl upload-prod-cli",
|
||||||
"deploy-prod-core": "cpl publish-core; cpl upload-prod-core",
|
"deploy-prod-core": "cpl publish-core; cpl upload-prod-core",
|
||||||
"deploy-prod-query": "cpl publish-query; cpl upload-prod-query",
|
"deploy-prod-query": "cpl publish-query; cpl upload-prod-query",
|
||||||
|
|
||||||
"pre-deploy-exp": "cpl sv $ARGS; cpl spu --environment=staging;",
|
"pre-deploy-exp": "cpl sv $ARGS; cpl spu --environment=staging;",
|
||||||
"deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-query;",
|
"deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-query;",
|
||||||
"de": "cpl deploy-exp $ARGS",
|
"de": "cpl deploy-exp $ARGS",
|
||||||
"deploy-exp-cli": "cpl publish-cli; cpl upload-exp-cli",
|
"deploy-exp-cli": "cpl publish-cli; cpl upload-exp-cli",
|
||||||
"deploy-exp-core": "cpl publish-core; cpl upload-exp-core",
|
"deploy-exp-core": "cpl publish-core; cpl upload-exp-core",
|
||||||
"deploy-exp-query": "cpl publish-query; cpl upload-exp-query",
|
"deploy-exp-query": "cpl publish-query; cpl upload-exp-query",
|
||||||
|
|
||||||
"pre-deploy-dev": "cpl sv $ARGS; cpl spu --environment=development;",
|
"pre-deploy-dev": "cpl sv $ARGS; cpl spu --environment=development;",
|
||||||
"deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-query;",
|
"deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-query;",
|
||||||
"dd": "cpl deploy-dev $ARGS",
|
"dd": "cpl deploy-dev $ARGS",
|
||||||
"deploy-dev-cli": "cpl publish-cli; cpl upload-dev-cli",
|
"deploy-dev-cli": "cpl publish-cli; cpl upload-dev-cli",
|
||||||
"deploy-dev-core": "cpl publish-core; cpl upload-dev-core",
|
"deploy-dev-core": "cpl publish-core; cpl upload-dev-core",
|
||||||
"deploy-dev-query": "cpl publish-query; cpl upload-dev-query",
|
"deploy-dev-query": "cpl publish-query; cpl upload-dev-query",
|
||||||
|
|
||||||
"dev-install": "cpl di-core; cpl di-cli; cpl di-query;",
|
"dev-install": "cpl di-core; cpl di-cli; cpl di-query;",
|
||||||
"di": "cpl dev-install",
|
"di": "cpl dev-install",
|
||||||
"di-core": "pip install cpl-core --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
"di-core": "pip install cpl-core --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "cpl-cli",
|
"Name": "cpl-cli",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "MIT",
|
"LicenseName": "MIT",
|
||||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0"
|
"cpl-core>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"DevDependencies": [],
|
"DevDependencies": [],
|
||||||
"PythonVersion": ">=3.10",
|
"PythonVersion": ">=3.10",
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "cpl-core",
|
"Name": "cpl-core",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
@ -59,6 +59,17 @@ class ServiceCollection(ServiceCollectionABC):
|
|||||||
for pipe in PipeABC.__subclasses__():
|
for pipe in PipeABC.__subclasses__():
|
||||||
self.add_transient(PipeABC, pipe)
|
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):
|
def add_singleton(self, service_type: Union[type, object], service: Union[type, object] = None):
|
||||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
||||||
return self
|
return self
|
||||||
|
@ -35,6 +35,11 @@ class ServiceCollectionABC(ABC):
|
|||||||
r"""Adds the CPL internal pipes as transient"""
|
r"""Adds the CPL internal pipes as transient"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def add_translation(self):
|
||||||
|
r"""Adds the CPL translation"""
|
||||||
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def add_transient(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
|
def add_transient(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
|
||||||
r"""Adds a service with transient lifetime
|
r"""Adds a service with transient lifetime
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "cpl-query",
|
"Name": "cpl-query",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "Sven Heidemann",
|
"Author": "Sven Heidemann",
|
||||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
1
src/cpl_translation/__init__.py
Normal file
1
src/cpl_translation/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# imports:
|
46
src/cpl_translation/cpl-translation.json
Normal file
46
src/cpl_translation/cpl-translation.json
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"ProjectSettings": {
|
||||||
|
"Name": "cpl-translation",
|
||||||
|
"Version": {
|
||||||
|
"Major": "2022",
|
||||||
|
"Minor": "8",
|
||||||
|
"Micro": "1.dev7"
|
||||||
|
},
|
||||||
|
"Author": "Sven Heidemann",
|
||||||
|
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||||
|
"Description": "sh-edraft Common Python library Translation",
|
||||||
|
"LongDescription": "sh-edraft Common Python library Python Translation",
|
||||||
|
"URL": "https://www.sh-edraft.de",
|
||||||
|
"CopyrightDate": "2022",
|
||||||
|
"CopyrightName": "sh-edraft.de",
|
||||||
|
"LicenseName": "MIT",
|
||||||
|
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||||
|
"Dependencies": [
|
||||||
|
"cpl-core>=2022.8.1.dev7"
|
||||||
|
],
|
||||||
|
"DevDependencies": [
|
||||||
|
"cpl-cli>=2022.6.0"
|
||||||
|
],
|
||||||
|
"PythonVersion": ">=3.10.4",
|
||||||
|
"PythonPath": {
|
||||||
|
"linux": "../../venv/bin/python"
|
||||||
|
},
|
||||||
|
"Classifiers": []
|
||||||
|
},
|
||||||
|
"BuildSettings": {
|
||||||
|
"ProjectType": "library",
|
||||||
|
"SourcePath": "",
|
||||||
|
"OutputPath": "../../dist",
|
||||||
|
"Main": "cpl_translation.main",
|
||||||
|
"EntryPoint": "cpl-translation",
|
||||||
|
"IncludePackageData": false,
|
||||||
|
"Included": [],
|
||||||
|
"Excluded": [
|
||||||
|
"*/__pycache__",
|
||||||
|
"*/logs",
|
||||||
|
"*/tests"
|
||||||
|
],
|
||||||
|
"PackageData": {},
|
||||||
|
"ProjectReferences": []
|
||||||
|
}
|
||||||
|
}
|
16
src/cpl_translation/translate_pipe.py
Normal file
16
src/cpl_translation/translate_pipe.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from cpl_core.console import Console
|
||||||
|
from cpl_core.pipes.pipe_abc import PipeABC
|
||||||
|
from cpl_translation.translation_service_abc import TranslationServiceABC
|
||||||
|
|
||||||
|
|
||||||
|
class TranslatePipe(PipeABC):
|
||||||
|
|
||||||
|
def __init__(self, translation: TranslationServiceABC):
|
||||||
|
self._translation = translation
|
||||||
|
|
||||||
|
def transform(self, value: any, *args):
|
||||||
|
try:
|
||||||
|
return self._translation.translate(value)
|
||||||
|
except KeyError as e:
|
||||||
|
Console.error(f'Translation {value} not found')
|
||||||
|
return ''
|
54
src/cpl_translation/translation_service.py
Normal file
54
src/cpl_translation/translation_service.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import json
|
||||||
|
import os.path
|
||||||
|
from functools import reduce
|
||||||
|
|
||||||
|
from cpl_core.console import Console
|
||||||
|
from cpl_translation.translation_service_abc import TranslationServiceABC
|
||||||
|
from cpl_translation.translation_settings import TranslationSettings
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationService(TranslationServiceABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._translation = {}
|
||||||
|
|
||||||
|
self._language = ''
|
||||||
|
self._default_language = ''
|
||||||
|
|
||||||
|
TranslationServiceABC.__init__(self)
|
||||||
|
|
||||||
|
def set_default_lang(self, lang: str):
|
||||||
|
self._default_language = lang
|
||||||
|
self.set_lang(lang)
|
||||||
|
|
||||||
|
def set_lang(self, lang: str):
|
||||||
|
self._language = lang
|
||||||
|
|
||||||
|
def load(self, lang: str):
|
||||||
|
if not os.path.exists(f'translation/{lang}.json'):
|
||||||
|
raise FileNotFoundError()
|
||||||
|
|
||||||
|
file_dict = {}
|
||||||
|
with open(f'translation/{lang}.json', 'r') as file:
|
||||||
|
file_dict = json.load(file)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
self._translation[lang] = file_dict
|
||||||
|
|
||||||
|
def load_by_settings(self, settings: TranslationSettings):
|
||||||
|
if settings is None:
|
||||||
|
raise Exception(f'{TranslationSettings.__name__} not loaded')
|
||||||
|
|
||||||
|
self._language = settings.default_language
|
||||||
|
self._default_language = settings.default_language
|
||||||
|
|
||||||
|
for lang in settings.languages:
|
||||||
|
self.load(lang)
|
||||||
|
|
||||||
|
def translate(self, key: str) -> str:
|
||||||
|
value = reduce(lambda d, key: d.get(key) if isinstance(d, dict) else None, key.split("."), self._translation[self._language])
|
||||||
|
|
||||||
|
if value is None:
|
||||||
|
raise KeyError(f'Translation {key} not found')
|
||||||
|
|
||||||
|
return value
|
22
src/cpl_translation/translation_service_abc.py
Normal file
22
src/cpl_translation/translation_service_abc.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationServiceABC(ABC):
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def __init__(self): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set_default_lang(self, lang: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def set_lang(self, lang: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def load(self, lang: str): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def load_by_settings(self): pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def translate(self, key: str) -> str: pass
|
29
src/cpl_translation/translation_settings.py
Normal file
29
src/cpl_translation/translation_settings.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import traceback
|
||||||
|
|
||||||
|
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||||
|
from cpl_core.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
class TranslationSettings(ConfigurationModelABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
ConfigurationModelABC.__init__(self)
|
||||||
|
|
||||||
|
self._languages = []
|
||||||
|
self._default_lang = ''
|
||||||
|
|
||||||
|
@property
|
||||||
|
def languages(self) -> list[str]:
|
||||||
|
return self._languages
|
||||||
|
|
||||||
|
@property
|
||||||
|
def default_language(self) -> str:
|
||||||
|
return self._default_lang
|
||||||
|
|
||||||
|
def from_dict(self, settings: dict):
|
||||||
|
try:
|
||||||
|
self._languages = settings['Languages']
|
||||||
|
self._default_lang = settings['DefaultLanguage']
|
||||||
|
except Exception as e:
|
||||||
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||||
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
0
src/tests/custom/translation/LICENSE
Normal file
0
src/tests/custom/translation/LICENSE
Normal file
0
src/tests/custom/translation/README.md
Normal file
0
src/tests/custom/translation/README.md
Normal file
9
src/tests/custom/translation/cpl-workspace.json
Normal file
9
src/tests/custom/translation/cpl-workspace.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"WorkspaceSettings": {
|
||||||
|
"DefaultProject": "translation",
|
||||||
|
"Projects": {
|
||||||
|
"translation": "src/translation/translation.json"
|
||||||
|
},
|
||||||
|
"Scripts": {}
|
||||||
|
}
|
||||||
|
}
|
1
src/tests/custom/translation/src/tests/__init__.py
Normal file
1
src/tests/custom/translation/src/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# imports:
|
1
src/tests/custom/translation/src/translation/__init__.py
Normal file
1
src/tests/custom/translation/src/translation/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
# imports:
|
29
src/tests/custom/translation/src/translation/application.py
Normal file
29
src/tests/custom/translation/src/translation/application.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from cpl_core.application import ApplicationABC
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.console import Console
|
||||||
|
from cpl_core.dependency_injection import ServiceProviderABC
|
||||||
|
from cpl_translation.translate_pipe import TranslatePipe
|
||||||
|
from cpl_translation.translation_service_abc import TranslationServiceABC
|
||||||
|
from cpl_translation.translation_settings import TranslationSettings
|
||||||
|
|
||||||
|
|
||||||
|
class Application(ApplicationABC):
|
||||||
|
|
||||||
|
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||||
|
ApplicationABC.__init__(self, config, services)
|
||||||
|
|
||||||
|
self._translate: TranslatePipe = services.get_service(TranslatePipe)
|
||||||
|
self._translation: TranslationServiceABC = services.get_service(TranslationServiceABC)
|
||||||
|
self._translation_settings: TranslationSettings = config.get_configuration(TranslationSettings)
|
||||||
|
|
||||||
|
self._translation.load_by_settings(config.get_configuration(TranslationSettings))
|
||||||
|
self._translation.set_default_lang('de')
|
||||||
|
|
||||||
|
def configure(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
Console.write_line(self._translate.transform('main.text.hello_world'))
|
||||||
|
self._translation.set_lang('en')
|
||||||
|
Console.write_line(self._translate.transform('main.text.hello_world'))
|
||||||
|
Console.write_line(self._translate.transform('main.text.hello'))
|
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"TimeFormatSettings": {
|
||||||
|
"DateFormat": "%Y-%m-%d",
|
||||||
|
"TimeFormat": "%H:%M:%S",
|
||||||
|
"DateTimeFormat": "%Y-%m-%d %H:%M:%S.%f",
|
||||||
|
"DateTimeLogFormat": "%Y-%m-%d_%H-%M-%S"
|
||||||
|
},
|
||||||
|
|
||||||
|
"LoggingSettings": {
|
||||||
|
"Path": "logs/",
|
||||||
|
"Filename": "log_$start_time.log",
|
||||||
|
"ConsoleLogLevel": "ERROR",
|
||||||
|
"FileLogLevel": "WARN"
|
||||||
|
},
|
||||||
|
|
||||||
|
"Translation": {
|
||||||
|
"Languages":[
|
||||||
|
"de",
|
||||||
|
"en"
|
||||||
|
],
|
||||||
|
"DefaultLanguage": "en"
|
||||||
|
}
|
||||||
|
}
|
14
src/tests/custom/translation/src/translation/main.py
Normal file
14
src/tests/custom/translation/src/translation/main.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from cpl_core.application import ApplicationBuilder
|
||||||
|
|
||||||
|
from translation.application import Application
|
||||||
|
from translation.startup import Startup
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app_builder = ApplicationBuilder(Application)
|
||||||
|
app_builder.use_startup(Startup)
|
||||||
|
app_builder.build().run()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
18
src/tests/custom/translation/src/translation/startup.py
Normal file
18
src/tests/custom/translation/src/translation/startup.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from cpl_core.application import StartupABC
|
||||||
|
from cpl_core.configuration import ConfigurationABC
|
||||||
|
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
|
||||||
|
from cpl_core.environment import ApplicationEnvironment
|
||||||
|
|
||||||
|
|
||||||
|
class Startup(StartupABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
StartupABC.__init__(self)
|
||||||
|
|
||||||
|
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||||
|
configuration.add_json_file('appsettings.json')
|
||||||
|
return configuration
|
||||||
|
|
||||||
|
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||||
|
services.add_translation()
|
||||||
|
return services.build_service_provider()
|
@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"ProjectSettings": {
|
||||||
|
"Name": "translation",
|
||||||
|
"Version": {
|
||||||
|
"Major": "0",
|
||||||
|
"Minor": "0",
|
||||||
|
"Micro": "0"
|
||||||
|
},
|
||||||
|
"Author": "",
|
||||||
|
"AuthorEmail": "",
|
||||||
|
"Description": "",
|
||||||
|
"LongDescription": "",
|
||||||
|
"URL": "",
|
||||||
|
"CopyrightDate": "",
|
||||||
|
"CopyrightName": "",
|
||||||
|
"LicenseName": "",
|
||||||
|
"LicenseDescription": "",
|
||||||
|
"Dependencies": [
|
||||||
|
"cpl-core>=2022.6.0"
|
||||||
|
],
|
||||||
|
"DevDependencies": [
|
||||||
|
"cpl-cli>=2022.6.0"
|
||||||
|
],
|
||||||
|
"PythonVersion": ">=3.10.4",
|
||||||
|
"PythonPath": {
|
||||||
|
"linux": ""
|
||||||
|
},
|
||||||
|
"Classifiers": []
|
||||||
|
},
|
||||||
|
"BuildSettings": {
|
||||||
|
"ProjectType": "console",
|
||||||
|
"SourcePath": "",
|
||||||
|
"OutputPath": "../../dist",
|
||||||
|
"Main": "translation.main",
|
||||||
|
"EntryPoint": "translation",
|
||||||
|
"IncludePackageData": false,
|
||||||
|
"Included": [],
|
||||||
|
"Excluded": [
|
||||||
|
"*/__pycache__",
|
||||||
|
"*/logs",
|
||||||
|
"*/tests"
|
||||||
|
],
|
||||||
|
"PackageData": {},
|
||||||
|
"ProjectReferences": []
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"main": {
|
||||||
|
"text": {
|
||||||
|
"hello_world": "Hallo Welt"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"main": {
|
||||||
|
"text": {
|
||||||
|
"hello_world": "Hello World"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "MIT",
|
"LicenseName": "MIT",
|
||||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1"
|
"cpl-core>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {},
|
"PythonPath": {},
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "MIT",
|
"LicenseName": "MIT",
|
||||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1",
|
"cpl-core>=2022.8.1.dev7",
|
||||||
"gitpython==3.1.27"
|
"gitpython==3.1.27"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "unittests",
|
"Name": "unittests",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0.rc1"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "",
|
"Author": "",
|
||||||
"AuthorEmail": "",
|
"AuthorEmail": "",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1"
|
"cpl-core>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "unittest_cli",
|
"Name": "unittest_cli",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0.rc1"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "",
|
"Author": "",
|
||||||
"AuthorEmail": "",
|
"AuthorEmail": "",
|
||||||
@ -16,8 +16,8 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1",
|
"cpl-core>=2022.8.1.dev7",
|
||||||
"cpl-cli>=2022.6.0.rc1"
|
"cpl-cli>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "unittest_core",
|
"Name": "unittest_core",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0.rc1"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "",
|
"Author": "",
|
||||||
"AuthorEmail": "",
|
"AuthorEmail": "",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1"
|
"cpl-core>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "unittest_query",
|
"Name": "unittest_query",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0.rc1"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "",
|
"Author": "",
|
||||||
"AuthorEmail": "",
|
"AuthorEmail": "",
|
||||||
@ -16,8 +16,8 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1",
|
"cpl-core>=2022.8.1.dev7",
|
||||||
"cpl-query>=2022.6.0.rc1"
|
"cpl-query>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
"Name": "unittest_shared",
|
"Name": "unittest_shared",
|
||||||
"Version": {
|
"Version": {
|
||||||
"Major": "2022",
|
"Major": "2022",
|
||||||
"Minor": "6",
|
"Minor": "8",
|
||||||
"Micro": "0.rc1"
|
"Micro": "1.dev7"
|
||||||
},
|
},
|
||||||
"Author": "",
|
"Author": "",
|
||||||
"AuthorEmail": "",
|
"AuthorEmail": "",
|
||||||
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"cpl-core>=2022.6.0.rc1"
|
"cpl-core>=2022.8.1.dev7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.10.4",
|
"PythonVersion": ">=3.10.4",
|
||||||
"PythonPath": {
|
"PythonPath": {
|
||||||
|
Loading…
Reference in New Issue
Block a user