tiramisu/tiramisu/i18n.py

34 lines
731 B
Python
Raw Normal View History

2013-04-13 23:09:05 +02:00
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
2013-05-23 14:55:52 +02:00
"internationalisation utilities"
2013-04-13 23:09:05 +02:00
import gettext
import os
import sys
import locale
# Application Name
APP_NAME = 'tiramisu'
# Traduction dir
2013-05-02 11:23:47 +02:00
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']
lc, encoding = locale.getdefaultlocale()
if lc:
languages = [lc]
languages += DEFAULT_LANG
mo_location = LOCALE_DIR
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)
2013-04-13 23:09:05 +02:00
_ = gettext.gettext