21 lines
534 B
Python
21 lines
534 B
Python
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')
|