Python locale 模块,textdomain() 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用locale.textdomain()

项目:pytimetrack    作者:fhackerz    | 项目源码 | 文件源码
def main():
    mark_time("in main()")

    root_logger = logging.getLogger()
    root_logger.addHandler(logging.StreamHandler())
    if '--debug' in sys.argv:
        root_logger.setLevel(logging.DEBUG)
    else:
        root_logger.setLevel(logging.INFO)

    # Tell GTK+ to use out translations
    locale.bindtextdomain('gtimelog', LOCALE_DIR)
    locale.textdomain('gtimelog')
    # Tell Python's gettext.gettext() to use our translations
    gettext.bindtextdomain('gtimelog', LOCALE_DIR)
    gettext.textdomain('gtimelog')

    # Make ^C terminate the process
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Run the app
    app = Application()
    mark_time("app created")
    sys.exit(app.run(sys.argv))
项目:cozy    作者:geigi    | 项目源码 | 文件源码
def __init__(self, **kwargs):
        self.ui = None

        GObject.threads_init()
        listen()

        Gtk.Application.__init__(self, application_id='com.github.geigi.cozy')

        GLib.setenv("PULSE_PROP_media.role", "music", True)

        import gettext

        locale.bindtextdomain('cozy', localedir)
        locale.textdomain('cozy')
        gettext.install('cozy', localedir)
项目:python-sense-emu    作者:RPi-Distro    | 项目源码 | 文件源码
def init_i18n(languages=None):
    # Ensure any resources we extract get cleaned up interpreter shutdown
    atexit.register(pkg_resources.cleanup_resources)
    # Figure out where the language catalogs are; this will extract them
    # if the package is frozen
    localedir = pkg_resources.resource_filename(__name__, 'locale')
    try:
        # Use the user's default locale instead of C
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        # If locale is not supported, use C which should at least provide
        # consistency. In this case, don't set a gettext domain to prevent
        # translation of strings
        locale.setlocale(locale.LC_ALL, 'C')
    else:
        # Set translation domain for GNU's gettext (needed by GTK's Builder)
        try:
            locale.bindtextdomain(__project__, localedir)
            locale.textdomain(__project__)
        except AttributeError:
            if sys.platform.startswith('win'):
                try:
                    # We're on Windows; try and use intl.dll instead
                    import ctypes
                    libintl = ctypes.cdll.LoadLibrary('intl.dll')
                except OSError:
                    # intl.dll isn't available; give up
                    return
                else:
                    libintl.bindtextdomain(__project__, localedir)
                    libintl.textdomain(__project__)
                    libintl.bind_textdomain_codeset(__project, 'UTF-8')
            else:
                # We're on something else (Mac OS X most likely); no idea what
                # to do here yet
                return
        # Finally, set translation domain for Python's built-in gettext
        _gettext.bindtextdomain(__project__, localedir)
        _gettext.textdomain(__project__)
项目:gpt    作者:encarsia    | 项目源码 | 文件源码
def __init__(self):

        #get current directory
        self.install_dir = os.getcwd()

        #set up logging
        FORMAT = "%(asctime)s %(funcName)-14s %(lineno)d| %(levelname)-8s | %(message)s"

        logging.basicConfig(filename='gpt.log',level=logging.DEBUG,filemode='w',format=FORMAT,datefmt="%H:%M:%S")
        self.log = logging.getLogger(__name__)

        #Glade files/window configuration
        gladefile_list = [  "tlcalculator.glade",
                            "gopro.glade",
                            "appwindow.glade",
                            "playerwindow.glade"]
        self.gladefile = []

        for f in gladefile_list:
            self.gladefile.append(os.path.join(self.install_dir,"herostuff",f))

        #css stylesheet
        self.stylesheet = os.path.join(self.install_dir,"herostuff","gtk.css")

        self.locales_dir = os.path.join(self.install_dir,'herostuff','po','locale')
        self.appname = 'GPT'

        #setting up localization
        locale.bindtextdomain(self.appname,self.locales_dir)
        locale.textdomain(self.locales_dir)      
        gettext.bindtextdomain(self.appname,self.locales_dir)
        gettext.textdomain(self.appname)

        #check for config file to set up working directory
        #create file in case it does not exist
        self.config = os.path.join(os.path.expanduser('~'),".config","gpt.conf")
        self.defaultwdir = os.path.join(os.path.expanduser('~'),"GP")

        if os.path.isfile(self.config) is False:
            self.stdir = self.defaultwdir
            self.chkdir(self.stdir)
            self.createconfig(self.stdir)
            self.kd_supp = True
        else:
            self.readconfig()
        self.show_message(_("Working directory: %s") % self.stdir)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
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