squirrel-battle/squirrelbattle/translations.py

29 lines
781 B
Python
Raw Normal View History

2020-11-27 19:32:40 +00:00
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
# SPDX-License-Identifier: GPL-3.0-or-later
import gettext
2020-11-27 19:53:24 +00:00
SUPPORTED_LOCALES = ["en", "fr"]
DEFAULT_LOCALE = "en"
_current_locale = DEFAULT_LOCALE
2020-11-27 19:32:40 +00:00
_TRANSLATORS = dict()
2020-11-27 19:53:24 +00:00
for language in SUPPORTED_LOCALES:
2020-11-27 19:32:40 +00:00
_TRANSLATORS[language] = gettext.translation("squirrelbattle",
localedir="locale",
languages=[language])
def gettext(message: str) -> str:
2020-11-27 19:53:24 +00:00
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