i18n with gettext

This commit is contained in:
2022-02-02 19:35:57 +01:00
parent 939c86dbe2
commit 9c28a41904
21 changed files with 686 additions and 437 deletions

20
raven/i18n.py Normal file
View File

@@ -0,0 +1,20 @@
import gettext
import os
from pathlib import Path
locale = os.environ['LANG'] if os.environ['LANG'] else "en"
_ = 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
except FileNotFoundError:
pass
if not _:
_ = gettext.gettext
ngettext = gettext.ngettext
print('No translation found')