Add possibility to change the language

This commit is contained in:
Yohann D'ANELLO
2020-11-27 20:53:24 +01:00
parent 2498fd2a61
commit 4287b4f045
5 changed files with 30 additions and 8 deletions

View File

@ -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