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