aboutsummaryrefslogtreecommitdiff
path: root/include/py/homekit/config/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'include/py/homekit/config/config.py')
-rw-r--r--include/py/homekit/config/config.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/include/py/homekit/config/config.py b/include/py/homekit/config/config.py
index 40ac211..3aa0e04 100644
--- a/include/py/homekit/config/config.py
+++ b/include/py/homekit/config/config.py
@@ -266,14 +266,26 @@ class TranslationUnit(BaseConfigUnit):
pass
+TranslationInstances = {}
+
+
class Translation:
LANGUAGES = ('en', 'ru')
DEFAULT_LANGUAGE = 'ru'
_langs: dict[str, TranslationUnit]
+ # def __init_subclass__(cls, **kwargs):
+ # super().__init_subclass__(**kwargs)
+ # cls._instance = None
+
+ def __new__(cls, *args, **kwargs):
+ unit = args[0]
+ if unit not in TranslationInstances:
+ TranslationInstances[unit] = super(Translation, cls).__new__(cls)
+ return TranslationInstances[unit]
+
def __init__(self, name: str):
- super().__init__()
self._langs = {}
for lang in self.LANGUAGES:
for dirname in CONFIG_DIRECTORIES:
@@ -289,7 +301,7 @@ class Translation:
if len(diff) > 0:
raise RuntimeError(f'{name}: translation units have difference in keys: ' + ', '.join(diff))
- def get(self, lang: str) -> TranslationUnit:
+ def get(self, lang: str = DEFAULT_LANGUAGE) -> TranslationUnit:
return self._langs[lang]