Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
feat(i18n): ✨ add lang specific param in translate method
Browse files Browse the repository at this point in the history
  • Loading branch information
AnzhiZhang committed Jul 2, 2022
1 parent 571923e commit 45d89e2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions utils/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ def __load(self):
with open(path, encoding='utf-8') as f:
self.__data[os.path.splitext(i)[0]] = yaml.safe_load(f)

def translate(self, key: str, *args) -> str:
def translate(self, key: str, *args, lang=None) -> str:
"""
Translate words from key.
:param key: Key of words.
:param lang: Language name.
:return: Words.
"""
return self.__data.get(self.__lang).get(key).format(*args)
if lang is None:
lang = self.__lang
return self.__data.get(lang).get(key).format(*args)

def get_languages_list(self) -> List[str]:
"""
Expand Down

0 comments on commit 45d89e2

Please sign in to comment.