当前位置: 首页>>代码示例>>Python>>正文


Python gettext.install方法代码示例

本文整理汇总了Python中gettext.install方法的典型用法代码示例。如果您正苦于以下问题:Python gettext.install方法的具体用法?Python gettext.install怎么用?Python gettext.install使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gettext的用法示例。


在下文中一共展示了gettext.install方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: install

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def install(domain):
    """Install a _() function using the given translation domain.

    Given a translation domain, install a _() function using gettext's
    install() function.

    The main difference from gettext.install() is that we allow
    overriding the default localedir (e.g. /usr/share/locale) using
    a translation-domain-specific environment variable (e.g.
    NOVA_LOCALEDIR).

    :param domain: the translation domain
    """
    from six import moves
    tf = _factory.TranslatorFactory(domain)
    moves.builtins.__dict__['_'] = tf.primary 
开发者ID:openstack,项目名称:oslo.i18n,代码行数:18,代码来源:_gettextutils.py

示例2: display_metadata

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def display_metadata(self, term_instance):
        """
        Sends a message to the user that displays the OGG file metadata.  Things
        like ID3 tags, bitrate, channels, etc.
        """
        if not self.sent_message:
            global _logged_mutagen_warning
            try:
                import mutagen.oggvorbis
            except ImportError:
                if not _logged_mutagen_warning:
                    _logged_mutagen_warning = True
                    logging.warning(_(
                        "Could not import the mutagen Python module.  "
                        "Displaying audio file metadata will be disabled."))
                    logging.info(_(
                        "TIP: Install mutagen:  sudo pip install mutagen"))
                return
            oggfile = mutagen.oggvorbis.Open(self.file_obj.name)
            message = "<pre>%s</pre>" % oggfile.pprint()
            term_instance.send_message(message)
            self.sent_message = True 
开发者ID:Wramberg,项目名称:TerminalView,代码行数:24,代码来源:terminal.py

示例3: test_the_alternative_interface

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def test_the_alternative_interface(self):
        eq = self.assertEqual
        # test the alternative interface
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        # Install the translation object
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        # Try unicode return type
        t.install(unicode=True)
        eq(_('mullusk'), 'bacon')
        # Test installation of other methods
        import __builtin__
        t.install(unicode=True, names=["gettext", "lgettext"])
        eq(_, t.ugettext)
        eq(__builtin__.gettext, t.ugettext)
        eq(lgettext, t.lgettext)
        del __builtin__.gettext
        del __builtin__.lgettext 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_gettext.py

示例4: install

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def install(domain):
    """Install a _() function using the given translation domain.

    Given a translation domain, install a _() function using gettext's
    install() function.

    The main difference from gettext.install() is that we allow
    overriding the default localedir (e.g. /usr/share/locale) using
    a translation-domain-specific environment variable (e.g.
    NOVA_LOCALEDIR).

    Note that to enable lazy translation, enable_lazy must be
    called.

    :param domain: the translation domain
    """
    from six import moves
    tf = TranslatorFactory(domain)
    moves.builtins.__dict__['_'] = tf.primary 
开发者ID:nttcom,项目名称:eclcli,代码行数:21,代码来源:gettextutils.py

示例5: setup_l10n

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [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

示例6: test_the_alternative_interface

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def test_the_alternative_interface(self):
        eq = self.assertEqual
        # test the alternative interface
        with open(self.mofile, 'rb') as fp:
            t = gettext.GNUTranslations(fp)
        # Install the translation object
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        # Try unicode return type
        t.install()
        eq(_('mullusk'), 'bacon')
        # Test installation of other methods
        import builtins
        t.install(names=["gettext", "lgettext"])
        eq(_, t.gettext)
        eq(builtins.gettext, t.gettext)
        eq(lgettext, t.lgettext)
        del builtins.gettext
        del builtins.lgettext 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_gettext.py

示例7: set_locale

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def set_locale(self, language_code, reuse=True):
        if not reuse or language_code not in self._locales:
            try:
                self._locales[language_code] = gettext.translation('hangupsbot', localedir=os.path.join(os.path.dirname(__file__), 'locale'), languages=[language_code])
                logger.debug("locale loaded: {}".format(language_code))
            except OSError:
                logger.exception("no translation for {}".format(language_code))

        if language_code in self._locales:
            self._locales[language_code].install()
            logger.info("locale: {}".format(language_code))
            return True

        else:
            logger.warning("LOCALE: {}".format(language_code))
            return False 
开发者ID:hangoutsbot,项目名称:hangoutsbot,代码行数:18,代码来源:hangupsbot.py

示例8: install_translation

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def install_translation():
    # Based on: (1) https://docs.python.org/3/library/gettext.html
    # (2) https://inventwithpython.com/blog/2014/12/20/translate-your-python-3-program-with-the-gettext-module/
    # Also see Readme.md#Localization for more info
    if settings.localization_language == "auto":
        # get the default locale using the locale module
        default_lang, _default_enc = locale.getdefaultlocale()
    else:
        default_lang = settings.localization_language
    try:
        if default_lang is not None:
            default_lang = [default_lang]
        lang = gettext.translation('AutoSimC', localedir='locale', languages=default_lang)
        lang.install()
        global translator
        translator = lang
    except FileNotFoundError:
        print("No translation for {} available.".format(default_lang)) 
开发者ID:SimCMinMax,项目名称:AutoSimC,代码行数:20,代码来源:main.py

示例9: test_the_alternative_interface

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def test_the_alternative_interface(self):
        eq = self.assertEqual
        # test the alternative interface
        fp = open(self.mofile, 'rb')
        t = gettext.GNUTranslations(fp)
        fp.close()
        # Install the translation object
        t.install()
        eq(_('nudge nudge'), 'wink wink')
        # Try unicode return type
        t.install(unicode=True)
        eq(_('mullusk'), 'bacon')
        # Test installation of other methods
        import __builtin__
        t.install(unicode=True, names=["gettext", "lgettext"])
        eq(_, t.ugettext)
        eq(__builtin__.gettext, t.ugettext)
        eq(lgettext, t.lgettext)
        del __builtin__.gettext
        del __builtin__.lgettext 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:22,代码来源:test_gettext.py

示例10: _init_config_builtin_delayed

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def _init_config_builtin_delayed(config):
  
  def _get_setting_source_name():
    if config.PLUGIN_NAME.startswith("plug_in"):
      return config.PLUGIN_NAME
    else:
      return "plug_in_" + config.PLUGIN_NAME
  
  if _gimp_dependent_modules_imported:
    config.SOURCE_NAME = _get_setting_source_name()
    config.SESSION_SOURCE = setting.SessionSource(config.SOURCE_NAME)
    config.PERSISTENT_SOURCE = setting.PersistentSource(config.SOURCE_NAME)
  
  gettext.install(config.DOMAIN_NAME, config.LOCALE_DIRPATH, unicode=True)
  
  if _gimp_dependent_modules_imported or config.LOG_MODE != "gimp_console":
    logging.log_output(
      config.LOG_MODE, config.PLUGINS_LOG_DIRPATHS,
      config.PLUGINS_LOG_STDOUT_FILENAME, config.PLUGINS_LOG_STDERR_FILENAME,
      config.PLUGIN_TITLE, config.GIMP_CONSOLE_MESSAGE_DELAY_MILLISECONDS) 
开发者ID:khalim19,项目名称:gimp-plugin-export-layers,代码行数:22,代码来源:__init__.py

示例11: __init__

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def __init__(self, conf):

		home = conf.home
		op_folder = conf.get('GENERAL', 'op_folder')+'/openplotter'
		locale_folder = home+op_folder+'/locale'
		language = conf.get('GENERAL', 'lang')

		gettext.install('openplotter', locale_folder, unicode=False)
		presLan_en = gettext.translation('openplotter', locale_folder, languages=['en'])
		presLan_ca = gettext.translation('openplotter', locale_folder, languages=['ca'])
		presLan_es = gettext.translation('openplotter', locale_folder, languages=['es'])
		presLan_fr = gettext.translation('openplotter', locale_folder, languages=['fr'])
		presLan_nl = gettext.translation('openplotter', locale_folder, languages=['nl'])
		presLan_de = gettext.translation('openplotter', locale_folder, languages=['de'])
		presLan_it = gettext.translation('openplotter', locale_folder, languages=['it'])
		presLan_eu = gettext.translation('openplotter', locale_folder, languages=['eu'])
		presLan_gl = gettext.translation('openplotter', locale_folder, languages=['gl'])

		if language=='en':presLan_en.install()
		if language=='ca':presLan_ca.install()
		if language=='es':presLan_es.install()
		if language=='fr':presLan_fr.install()
		if language=='nl':presLan_nl.install()
		if language=='de':presLan_de.install()
		if language=='it':presLan_it.install()
		if language=='eu':presLan_eu.install()
		if language=='gl':presLan_gl.install() 
开发者ID:sailoog,项目名称:openplotter,代码行数:29,代码来源:language.py

示例12: setUp

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def setUp(self):
        GettextBaseTest.setUp(self)
        self.localedir = os.curdir
        self.mofile = MOFILE
        gettext.install('gettext', self.localedir) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:7,代码来源:test_gettext.py

示例13: enable_lazy

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def enable_lazy():
    """Convenience function for configuring _() to use lazy gettext

    Call this at the start of execution to enable the gettextutils._
    function to use lazy gettext functionality. This is useful if
    your project is importing _ directly instead of using the
    gettextutils.install() way of importing the _ function.
    """
    global USE_LAZY
    USE_LAZY = True 
开发者ID:nttcom,项目名称:eclcli,代码行数:12,代码来源:gettextutils.py

示例14: __init__

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def __init__(self, language=None):
        """
        Initializes our object, if a language is specified, then we
        initialize ourselves to that, otherwise we use whatever we detect
        from the local operating system. If all else fails, we resort to the
        defined default_language.

        """

        # Cache previously loaded translations
        self._gtobjs = {}

        # Get our language
        self.lang = AppriseLocale.detect_language(language)

        if GETTEXT_LOADED is False:
            # We're done
            return

        if self.lang:
            # Load our gettext object and install our language
            try:
                self._gtobjs[self.lang] = gettext.translation(
                    DOMAIN, localedir=LOCALE_DIR, languages=[self.lang])

                # Install our language
                self._gtobjs[self.lang].install()

            except IOError:
                # This occurs if we can't access/load our translations
                pass 
开发者ID:caronc,项目名称:apprise,代码行数:33,代码来源:AppriseLocale.py

示例15: init

# 需要导入模块: import gettext [as 别名]
# 或者: from gettext import install [as 别名]
def init():
    """ Install gettext with the default parameters """
    if "_" not in builtins.__dict__:  # avoid installing lang two times
        os.environ["LANGUAGE"] = inginious_container_api.input.get_lang()
        if inginious_container_api.DEBUG:
            gettext.install("messages", get_lang_dir_path())
        else:
            gettext.install("messages", get_lang_dir_path()) 
开发者ID:UCL-INGI,项目名称:INGInious,代码行数:10,代码来源:lang.py


注:本文中的gettext.install方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。