Skip to content

Commit

Permalink
feat: multi lang (framework)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antares0982 committed May 5, 2024
1 parent 1fb81a3 commit 4b731cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Empty file.
Empty file.
27 changes: 27 additions & 0 deletions antares_bot/multi_lang/lang_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import TYPE_CHECKING

class LanguageMeta(type):
if TYPE_CHECKING:
SUPPORTED: tuple[str]

def __getattribute__(cls, name: str):
if name != '_LANG_INDEXED__':
if name == 'SUPPORTED' or name.startswith('__'):
return super().__getattribute__(name)
else:
return super().__getattribute__(name)
if not hasattr(cls, '_LANG_INDEXED__'):
lang_indexed = {}
cls._LANG_INDEXED__ = lang_indexed
for i, lang in enumerate(cls.SUPPORTED):
lang_indexed[lang] = i
else:
lang_indexed = super().__getattribute__('_LANG_INDEXED__')
index = lang_indexed.get(get_context(), 0)
l = super().__getattribute__(name)
if index >= len(l):
index = 0
ret = l[index]
if ret is None:
ret = l[0]
return ret

0 comments on commit 4b731cb

Please sign in to comment.