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


Python Translations.merge方法代码示例

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


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

示例1: lookup_translation

# 需要导入模块: from babel.support import Translations [as 别名]
# 或者: from babel.support.Translations import merge [as 别名]
 def lookup_translation():
     ctx = _request_ctx_stack.top
     if ctx is None:
         return None
     translations = getattr(ctx, 'pycroft_translations', None)
     if translations is None:
         translations = Translations()
         for module in (pycroft, web):
             os.path.dirname(module.__file__)
             dirname = os.path.join(ctx.app.root_path, 'translations')
             translations.merge(Translations.load(dirname, [get_locale()]))
         ctx.pycroft_translations = translations
     return translations
开发者ID:agdsn,项目名称:pycroft,代码行数:15,代码来源:server_run.py

示例2: _load_domain

# 需要导入模块: from babel.support import Translations [as 别名]
# 或者: from babel.support.Translations import merge [as 别名]
    def _load_domain(self, domain, fallback=True):
        """Load the given domain from one of the pre-configured locale dirs.

        Returns a :class:`gettext.NullTranslations` instance if no
        translations could be found for a non-critical domain. This
        allows untranslated plugins to be rendered in English instead
        of an error being raised.

        :param domain: A domain name.
        :param fallback: An optional flag that, when True, returns a
            :class:`gettext.NullTranslations` instance if no translations
            file could be found for the given language(s).
        :rtype: :class:`gettext.GNUTranslations`
        :returns: The native python translator instance for this domain.
        :raises DomainError: If no locale dir has been configured for this
            domain and the fallback is off.
        :raises LanguageError: If no translations could be found for this
            domain in this locale and the fallback is off.
        """
        locale_dirs = self._locale_dirs.get(domain, None)
        if locale_dirs:
            if isinstance(locale_dirs, basestring):
                locale_dirs = (locale_dirs, )
            translation_list = self._load_translations(domain, locale_dirs, fallback)
            if (not fallback) and len(translation_list) == 0:
                msg = 'No %r translations found for %r in %r.'
                raise LanguageError(msg % (domain, self._languages, locale_dirs))
            translations = Translations(domain=domain)
            for translation in translation_list:
                translations.merge(translation)
        elif fallback:
            translations = NullTranslations()
        else:
            raise DomainError('No localedir specified for domain %r' % domain)
        self._domains[domain] = translations
        return translations
开发者ID:MatrixFrog,项目名称:mediadrop,代码行数:38,代码来源:i18n.py


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