Add possibility to change the language
This commit is contained in:
@ -4,12 +4,25 @@
|
||||
import gettext
|
||||
|
||||
|
||||
SUPPORTED_LOCALES = ["en", "fr"]
|
||||
DEFAULT_LOCALE = "en"
|
||||
|
||||
_current_locale = DEFAULT_LOCALE
|
||||
|
||||
_TRANSLATORS = dict()
|
||||
for language in ["en", "fr"]:
|
||||
for language in SUPPORTED_LOCALES:
|
||||
_TRANSLATORS[language] = gettext.translation("squirrelbattle",
|
||||
localedir="locale",
|
||||
languages=[language])
|
||||
|
||||
|
||||
def gettext(message: str) -> str:
|
||||
return _TRANSLATORS.get("en", _TRANSLATORS.get("en")).gettext(message)
|
||||
return _TRANSLATORS.get(_current_locale,
|
||||
_TRANSLATORS.get("en")).gettext(message)
|
||||
|
||||
|
||||
def setlocale(lang: str) -> None:
|
||||
global _current_locale
|
||||
lang = lang[:2]
|
||||
if lang in SUPPORTED_LOCALES:
|
||||
_current_locale = lang
|
||||
|
Reference in New Issue
Block a user