tiramisu/tiramisu/i18n.py

39 lines
828 B
Python

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"internationalisation utilities"
import gettext
import os
import sys
import locale
# Application Name
APP_NAME = 'tiramisu'
# Traduction dir
APP_DIR = os.path.join(sys.prefix, 'share')
LOCALE_DIR = os.path.join(APP_DIR, 'locale')
# Default Lanugage
DEFAULT_LANG = os.environ.get('LANG', '').split(':')
DEFAULT_LANG += ['en_US']
languages = []
lc, encoding = locale.getdefaultlocale()
if lc:
languages = [lc]
languages += DEFAULT_LANG
mo_location = LOCALE_DIR
if sys.version_info[0] >= 3:
gettext.install(True, localedir=None)
else:
gettext.install(True, localedir=None, unicode=1)
gettext.find(APP_NAME, mo_location)
gettext.textdomain(APP_NAME)
gettext.bind_textdomain_codeset(APP_NAME, "UTF-8")
gettext.translation(APP_NAME, fallback=True)
_ = gettext.gettext