Files
krowlog/src/i18n.py
2022-02-22 19:47:40 +01:00

27 lines
779 B
Python

import gettext
from pathlib import Path
from src.pluginregistry import PluginRegistry
from src.settings.settingsstore import SettingsStore
from locale import getlocale
settings = SettingsStore.load()
locale = getlocale()[0]
locale = settings.session.get('general', 'lang', fallback=locale)
_ = False
src_dir = Path(__file__).resolve().parent.parent
try:
translation = gettext.translation('messages', localedir=src_dir / 'locales', languages=[locale])
if translation:
translation.install()
_ = translation.gettext
ngettext = translation.ngettext
PluginRegistry.execute("set_locale", locale)
except FileNotFoundError:
pass
if not _:
_ = gettext.gettext
ngettext = gettext.ngettext
PluginRegistry.execute("set_locale", '')