def _install(domain, localedir, asglobal=False):
'''
:param domain: translation domain
:param localedir: locale directory
:param asglobal: if True, installs the function _() in Python’s
builtin namespace. Default is False
Private function doing all the work for the :func:`elib.intl.install` and
:func:`elib.intl.install_module` functions.
'''
# prep locale system
if asglobal:
locale.setlocale(locale.LC_ALL, '')
# on windows systems, set the LANGUAGE environment variable
if sys.platform == 'win32' or sys.platform == 'nt':
_putenv('LANGUAGE', _getscreenlanguage())
# The locale module on Max OS X lacks bindtextdomain so we specifically
# test on linux2 here. See commit 4ae8b26fd569382ab66a9e844daa0e01de409ceb
if sys.platform == 'linux2':
locale.bindtextdomain(domain, localedir)
locale.bind_textdomain_codeset(domain, 'UTF-8')
locale.textdomain(domain)
# initialize Python's gettext interface
gettext.bindtextdomain(domain, localedir)
gettext.bind_textdomain_codeset(domain, 'UTF-8')
if asglobal:
gettext.textdomain(domain)
# on windows systems, initialize libintl
if sys.platform == 'win32' or sys.platform == 'nt':
from ctypes import cdll
libintl = cdll.intl
libintl.bindtextdomain(domain, localedir)
libintl.bind_textdomain_codeset(domain, 'UTF-8')
if asglobal:
libintl.textdomain(domain)
del libintl
评论列表
文章目录