i18n with gettext
This commit is contained in:
20
raven/i18n.py
Normal file
20
raven/i18n.py
Normal 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')
|
||||
Reference in New Issue
Block a user