當前位置: 首頁>>代碼示例>>Python>>正文


Python locale.bindtextdomain方法代碼示例

本文整理匯總了Python中locale.bindtextdomain方法的典型用法代碼示例。如果您正苦於以下問題:Python locale.bindtextdomain方法的具體用法?Python locale.bindtextdomain怎麽用?Python locale.bindtextdomain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在locale的用法示例。


在下文中一共展示了locale.bindtextdomain方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_l10n

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def setup_l10n(logger=None):
    """Setup RAFCON for localization

    Specify the directory, where the translation files (*.mo) can be found (rafcon/locale/) and set localization domain
    ("rafcon").

    :param logger: which logger to use for printing (either logging.log or distutils.log)
    """
    try:
        locale.setlocale(locale.LC_ALL, '')
    except locale.Error as e:
        logger and logger.warning("Cannot setup translations: {}".format(e))

    localedir = resource_filename('rafcon', 'locale')

    # Install gettext globally: Allows to use _("my string") without further imports
    gettext.install('rafcon', localedir)

    # Required for glade and the GtkBuilder
    locale.bindtextdomain('rafcon', localedir)
    locale.textdomain('rafcon') 
開發者ID:DLR-RM,項目名稱:RAFCON,代碼行數:23,代碼來源:i18n.py

示例2: _win_bindtextdomain

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def _win_bindtextdomain(self, localedomain, localedir):
        """
        Help routine for loading and setting up libintl attributes
        Returns libintl
        """
        from ctypes import cdll
        try:
            libintl = cdll.LoadLibrary('libintl-8')
            libintl.bindtextdomain(localedomain, localedir)
            libintl.textdomain(localedomain)
            libintl.bind_textdomain_codeset(localedomain, "UTF-8")

        except WindowsError:
            LOG.warning("Localization library libintl not on %PATH%, localization will be incomplete") 
開發者ID:GenealogyCollective,項目名稱:gprime,代碼行數:16,代碼來源:locale.py

示例3: switch_locale

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def switch_locale(self, locale_type):
            """
            Change the locale
            """
            locale.setlocale(locale.LC_ALL, '')
            locale.bindtextdomain(locale_type, RB.locale_dir())
            locale.textdomain(locale_type)
            gettext.bindtextdomain(locale_type, RB.locale_dir())
            gettext.textdomain(locale_type)
            gettext.install(locale_type) 
開發者ID:fossfreedom,項目名稱:alternative-toolbar,代碼行數:12,代碼來源:alttoolbar_preferences.py

示例4: __init__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def __init__(self):

        setproctitle.setproctitle("GPT")
        self.install_dir = os.getcwd()
        self.user_app_dir = os.path.join(os.path.expanduser("~"),
                                         ".config",
                                         "gpt",
                                         )
        # create hidden app folder in user"s home directory if it does
        # not exist
        if not os.path.isdir(self.user_app_dir):
            os.makedirs(self.user_app_dir)

        # initiate GTK+ application
        GLib.set_prgname("GPT")

        # set up logging
        os.chdir(self.user_app_dir)
        self.log = logging.getLogger("gpt")
        with open(os.path.join(self.install_dir, "logging.yaml")) as f:
            config = yaml.load(f)
            logging.config.dictConfig(config)

        self.loglevels = {"critical": 50,
                          "error": 40,
                          "warning": 30,
                          "info": 20,
                          "debug": 10,
                          }

        # log version info for debugging
        self.log.debug("Application version: {}".format(__version__))
        self.log.debug("GTK+ version: {}.{}.{}".format(Gtk.get_major_version(),
                                                          Gtk.get_minor_version(),
                                                          Gtk.get_micro_version(),
                                                          ))
        self.log.debug(_("Application executed from {}").format(self.install_dir))

        self.locales_dir = os.path.join(self.install_dir, "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(self.user_app_dir, "config.py")
        self.defaultwdir = os.path.join(os.path.expanduser("~"), "GP")

        if os.path.isfile(self.config):
            self.readconfig()
        else:
            self.stdir = self.defaultwdir
            self.chkdir(self.stdir)
            self.createconfig(self.stdir)
            self.kd_supp = True

        self.show_message(_("Working directory: {}").format(self.stdir)) 
開發者ID:encarsia,項目名稱:gpt,代碼行數:63,代碼來源:modules.py

示例5: __init__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate

        self.label = _('Sources Index')
        self.base = os.path.dirname(__file__)

        ManagedWindow.__init__(self, uistate,[], self.__class__)
        self.set_window(Gtk.Window(),Gtk.Label(),'')

        tool.Tool.__init__(self, dbstate, options_class, name)

        glade_file = os.path.join(USER_PLUGINS, "SourceIndex", "census.glade")

        if gramps.gen.constfunc.lin():
            import locale
            locale.setlocale(locale.LC_ALL, '')
            # This is needed to make gtk.Builder work by specifying the
            # translations directory
            locale.bindtextdomain("addon", self.base + "/locale")

            self.glade = Gtk.Builder()
            self.glade.set_translation_domain("addon")

            self.glade.add_from_file(glade_file)

            from gi.repository import GObject
            GObject.GObject.__init__(self.glade)

            window = self.glade.get_object('edit_census')

            self.set_window(window, self.glade.get_object('title'), self.label)

            self.ok_button = self.glade.get_object('ok')
            self.quit_button = self.glade.get_object('cancel')

        else:

            # Glade class from gui/glade.py and gui/managedwindow.py
            self.top = Glade()
            window = self.top.toplevel
            self.set_window(window, None, glade_file)

            self.ok_button = self.top.get_object('ok')
            self.quit_button = self.top.get_object('cancel')

        self.ok_button.connect('clicked', self.close)
        self.quit_button.connect('clicked', self.close)

        self.window.show()

        # tests
        filename = os.path.join(USER_PLUGINS, 'SourceIndex', 'test_census.xml')
        self.pname = self.pfname = 'éàèôÖàçèœ'
        self.write_xml(
            filename,
            'C0001',
            '',
            self.pfname,
            self.pname
            )
        self.parse_xml(filename) 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:63,代碼來源:census.py

示例6: __init__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate

        self.label = _('Sources Index')
        self.base = os.path.dirname(__file__)

        ManagedWindow.__init__(self, uistate,[], self.__class__)
        self.set_window(Gtk.Window(),Gtk.Label(),'')

        tool.Tool.__init__(self, dbstate, options_class, name)

        glade_file = os.path.join(USER_PLUGINS, "SourceIndex", "witness.glade")

        if gramps.gen.constfunc.lin():
            import locale
            locale.setlocale(locale.LC_ALL, '')
            # This is needed to make gtk.Builder work by specifying the
            # translations directory
            locale.bindtextdomain("addon", self.base + "/locale")

            self.glade = Gtk.Builder()
            self.glade.set_translation_domain("addon")

            self.glade.add_from_file(glade_file)

            from gi.repository import GObject
            GObject.GObject.__init__(self.glade)

            window = self.glade.get_object('witness_editor')

            self.set_window(window, self.glade.get_object('title'), self.label)

            self.ok_button = self.glade.get_object('ok')
            self.quit_button = self.glade.get_object('cancel')

        else:

            # Glade class from gui/glade.py and gui/managedwindow.py
            self.top = Glade()
            window = self.top.toplevel
            self.set_window(window, None, glade_file)

            self.ok_button = self.top.get_object('ok')
            self.quit_button = self.top.get_object('cancel')

        self.ok_button.connect('clicked', self.close)
        self.quit_button.connect('clicked', self.close)

        self.window.show() 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:51,代碼來源:witness.py

示例7: __init__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def __init__(self, dbstate, user, options_class, name, callback=None):
        uistate = user.uistate

        self.label = _('Sources Index')
        self.base = os.path.dirname(__file__)

        ManagedWindow.__init__(self, uistate,[], self.__class__)
        self.set_window(Gtk.Window(),Gtk.Label(),'')

        tool.Tool.__init__(self, dbstate, options_class, name)

        glade_file = os.path.join(USER_PLUGINS, "SourceIndex", "index.glade")

        if gramps.gen.constfunc.lin():
            import locale
            locale.setlocale(locale.LC_ALL, '')
            # This is needed to make gtk.Builder work by specifying the
            # translations directory
            locale.bindtextdomain("addon", self.base + "/locale")

            self.glade = Gtk.Builder()
            self.glade.set_translation_domain("addon")

            self.glade.add_from_file(glade_file)

            from gi.repository import GObject
            GObject.GObject.__init__(self.glade)

            self.top = self.glade.get_object('edit_index')

            self.set_window(self.top, self.glade.get_object('title'), self.label)

            self.birth_button = self.glade.get_object('add_b')
            self.death_button = self.glade.get_object('add_d')
            self.marriage_button = self.glade.get_object('add_m')
            self.census_button = self.glade.get_object('add_c')

            self.birth_button.connect('clicked', self.birth_editor)
            self.death_button.connect('clicked', self.death_editor)
            self.marriage_button.connect('clicked', self.marriage_editor)
            self.census_button.connect('clicked', self.census_editor)

        else:

            # Glade class from gui/glade.py and gui/managedwindow.py
            self.define_glade('edit_index', glade_file)
            self.set_window(self._gladeobj.toplevel, None, text=None, msg='Index')

            self.connect_button('add_b', self.birth_editor)
            self.connect_button('add_m', self.marriage_editor)
            self.connect_button('add_d', self.death_editor)
            self.connect_button('add_c', self.census_editor)

        #self.window.connect('delete-event', GladeHandlers.on_quit_clicked)

        self.window.show()

    # happy mixture ! 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:60,代碼來源:index.py

示例8: birth_editor

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def birth_editor(self, widget, data=None):
        """
        Experimental call of the birth editor (see rather 'birth.py')
        """

        glade_file = os.path.join(USER_PLUGINS, "SourceIndex", "birth.glade")

        if gramps.gen.constfunc.lin():
            import locale
            locale.setlocale(locale.LC_ALL, '')
            # This is needed to make gtk.Builder work by specifying the
            # translations directory
            locale.bindtextdomain("addon", self.base + "/locale")

            self.glade = Gtk.Builder()
            self.glade.set_translation_domain("addon")

            self.glade.add_from_file(glade_file)

            from gi.repository import GObject
            GObject.GObject.__init__(self.glade)

            b = self.glade.get_object('edit_birth')

            self.set_window(b, self.glade.get_object('title'), self.label)

            #self.wit_button = self.glade.get_object('add_wit')
            self.ok_button = self.glade.get_object('ok')
            self.quit_button = self.glade.get_object('cancel')

        else:

            # Glade class from gui/glade.py and gui/managedwindow.py
            top = Glade(glade_file)
            b = top.toplevel
            self.set_window(b, title=None, text=glade_file)

            #self.wit_button = top.get_object('add_wit')
            self.ok_button = top.get_object('ok')
            self.quit_button = top.get_object('cancel')

        #self.wit_button.connect('clicked', GtkHandlers.on_witness_clicked)
        self.ok_button.connect('clicked', self.close)
        self.quit_button.connect('clicked', self.close)

        #add_item()
        #close_item()
        #close_track()

        #b.connect('delete-event', GladeHandlers.on_quit_clicked)

        #b.hide()
        b.show() 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:55,代碼來源:index.py

示例9: death_editor

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def death_editor(self, widget, data=None):
        """
        Experimental call of the death editor (see rather 'death.py')
        """

        glade_file = os.path.join(USER_PLUGINS, "SourceIndex", "death.glade")

        if gramps.gen.constfunc.lin():
            import locale
            locale.setlocale(locale.LC_ALL, '')
            # This is needed to make gtk.Builder work by specifying the
            # translations directory
            locale.bindtextdomain("addon", self.base + "/locale")

            self.glade = Gtk.Builder()
            self.glade.set_translation_domain("addon")

            self.glade.add_from_file(glade_file)

            from gi.repository import GObject
            GObject.GObject.__init__(self.glade)

            d = self.glade.get_object('edit_death')

            self.set_window(d, self.glade.get_object('title'), self.label)

            #self.wit_button = self.glade.get_object('add_wit')
            self.ok_button = self.glade.get_object('ok')
            self.quit_button = self.glade.get_object('cancel')

        else:

            # Glade class from gui/glade.py and gui/managedwindow.py
            top = Glade(glade_file)
            d = top.toplevel
            self.set_window(d, title=None, text=glade_file)

            #self.wit_button = top.get_object('add_wit')
            self.ok_button = top.get_object('ok')
            self.quit_button = top.get_object('cancel')

        #self.wit_button.connect('clicked', GtkHandlers.on_witness_clicked)
        self.ok_button.connect('clicked', self.close)
        self.quit_button.connect('clicked', self.close)

        #d.hide()
        d.show()
        #d.connect("destroy", self.close) 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:50,代碼來源:index.py

示例10: census_editor

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def census_editor(self, widget, data=None):
        """
        Experimental call of the census editor (see rather 'census.py')
        """

        glade_file = os.path.join(USER_PLUGINS, "SourceIndex", "census.glade")

        if gramps.gen.constfunc.lin():
            import locale
            locale.setlocale(locale.LC_ALL, '')
            # This is needed to make gtk.Builder work by specifying the
            # translations directory
            locale.bindtextdomain("addon", self.base + "/locale")

            self.glade = Gtk.Builder()
            self.glade.set_translation_domain("addon")

            self.glade.add_from_file(glade_file)

            from gi.repository import GObject
            GObject.GObject.__init__(self.glade)

            c = self.glade.get_object('edit_census')

            self.set_window(c, self.glade.get_object('title'), self.label)

            self.ok_button = self.glade.get_object('ok')
            self.quit_button = self.glade.get_object('cancel')

        else:

            # Glade class from gui/glade.py and gui/managedwindow.py
            top = Glade(glade_file)
            c = top.toplevel
            self.set_window(c, title=None, text=glade_file)

            self.ok_button = top.get_object('ok')
            self.quit_button = top.get_object('cancel')

        self.ok_button.connect('clicked', self.close)
        self.quit_button.connect('clicked', self.close)

        #c.hide()
        c.show()
        #c.connect("destroy", self.close)


    # PyXMLFAQ -- Python XML Frequently Asked Questions
    # Author: 	Dave Kuhlman
    # dkuhlman@rexx.com
    # http://www.rexx.com/~dkuhlman 
開發者ID:gramps-project,項目名稱:addons-source,代碼行數:53,代碼來源:index.py

示例11: __init__

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def __init__(self):
        # The translation files will be under
        # @locale_dir@/@LANGUAGE@/LC_MESSAGES/@app_name@.mo
        self.app_name = "innstereo"
        app_dir = abspath(os.path.dirname(__file__))

        # Locale are stored in innstereo/locale
        # .mo files will then be located in innstereo/locale/LANGUAGECODE/LC_MESSAGES/
        locale_dir = abspath(join(app_dir, "locale"))

        if sys.platform == "win32":
            # Set $LANG on MS Windows for gettext
            if os.getenv('LANG') is None:
                lang, enc = locale.getdefaultlocale() #lang is POSIX e.g. de_DE
                os.environ['LANG'] = lang
                languages = [lang]

            # Set LOCALE_DIR for MS Windows
            import ctypes
            LIB_INTL = abspath(join(app_dir, "../gnome/libintl-8.dll"))
            libintl = ctypes.cdll.LoadLibrary(LIB_INTL)
            lc = locale.setlocale(locale.LC_ALL, "")
            locale_dir_g = abspath(join(app_dir, "locale"))
            libintl.bindtextdomain(self.app_name, locale_dir_g)
            libintl.bind_textdomain_codeset(self.app_name, "UTF-8")
        else:
            kwargs = {}
            if sys.version < '3':
                kwargs['unicode'] = 1
            gettext.install(True, localedir=None, **kwargs)

            gettext.find(self.app_name, locale_dir)
            locale.bindtextdomain(self.app_name, locale_dir)

        # Now we need to choose the language. We will provide a list, and gettext
        # will use the first translation available in the list
        default_languages = os.environ.get('LANG', '').split(':')
        default_languages += ['en_US']

        lc, encoding = locale.getdefaultlocale()
        if lc:
            languages = [lc]

        # Concat all languages (env + default locale),
        # and here we have the languages and location of the translations
        languages += default_languages

        gettext.bindtextdomain (self.app_name, locale_dir)
        gettext.textdomain (self.app_name)

        self._language = gettext.translation(self.app_name, locale_dir,
                                             languages=languages, fallback=True) 
開發者ID:innstereo,項目名稱:innstereo,代碼行數:54,代碼來源:i18n.py

示例12: _install

# 需要導入模塊: import locale [as 別名]
# 或者: from locale import bindtextdomain [as 別名]
def _install(domain, localedir, asglobal=False, libintl='intl'):
    '''
    :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 libintl and (sys.platform == 'win32' or sys.platform == 'nt'):
        from ctypes import cdll
        libintl = cdll.LoadLibrary(libintl)
        libintl.bindtextdomain(domain, localedir)
        libintl.bind_textdomain_codeset(domain, 'UTF-8')

        if asglobal:
            libintl.textdomain(domain)

        del libintl 
開發者ID:jendrikseipp,項目名稱:rednotebook,代碼行數:44,代碼來源:elibintl.py


注:本文中的locale.bindtextdomain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。