28 lines
859 B
Python
28 lines
859 B
Python
import gettext
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from raven.pluginregistry import PluginRegistry
|
|
from raven.settings.settingsstore import SettingsStore
|
|
|
|
settings = SettingsStore.load()
|
|
locale = os.environ['LANG'] if 'LANG' in os.environ and os.environ['LANG'] else "en"
|
|
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", '')
|
|
print('No translation found')
|