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


Python trans_real._active方法代码示例

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


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

示例1: reset_translations

# 需要导入模块: from django.utils.translation import trans_real [as 别名]
# 或者: from django.utils.translation.trans_real import _active [as 别名]
def reset_translations():
    import gettext
    from django.utils.translation import trans_real
    gettext._translations = {}
    trans_real._translations = {}
    trans_real._default = None
    trans_real._active = threading.local() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:9,代码来源:autoreload.py

示例2: language_changed

# 需要导入模块: from django.utils.translation import trans_real [as 别名]
# 或者: from django.utils.translation.trans_real import _active [as 别名]
def language_changed(**kwargs):
    if kwargs['setting'] in {'LANGUAGES', 'LANGUAGE_CODE', 'LOCALE_PATHS'}:
        from django.utils.translation import trans_real
        trans_real._default = None
        trans_real._active = threading.local()
    if kwargs['setting'] in {'LANGUAGES', 'LOCALE_PATHS'}:
        from django.utils.translation import trans_real
        trans_real._translations = {}
        trans_real.check_for_language.cache_clear() 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:11,代码来源:signals.py

示例3: test_resets_trans_real

# 需要导入模块: from django.utils.translation import trans_real [as 别名]
# 或者: from django.utils.translation.trans_real import _active [as 别名]
def test_resets_trans_real(self):
        trans_real._translations = {'foo': 'bar'}
        trans_real._default = 1
        trans_real._active = False
        autoreload.reset_translations()
        self.assertEqual(trans_real._translations, {})
        self.assertIsNone(trans_real._default)
        self.assertIsInstance(trans_real._active, _thread._local) 
开发者ID:nesdis,项目名称:djongo,代码行数:10,代码来源:test_autoreload.py

示例4: test_template_tags_pgettext

# 需要导入模块: from django.utils.translation import trans_real [as 别名]
# 或者: from django.utils.translation.trans_real import _active [as 别名]
def test_template_tags_pgettext(self):
        """{% trans %} takes message contexts into account (#14806)."""
        trans_real._active = local()
        trans_real._translations = {}
        with translation.override('de'):
            # Nonexistent context...
            t = Template('{% load i18n %}{% trans "May" context "nonexistent" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'May')

            # Existing context... using a literal
            t = Template('{% load i18n %}{% trans "May" context "month name" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Mai')
            t = Template('{% load i18n %}{% trans "May" context "verb" %}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Kann')

            # Using a variable
            t = Template('{% load i18n %}{% trans "May" context message_context %}')
            rendered = t.render(Context({'message_context': 'month name'}))
            self.assertEqual(rendered, 'Mai')
            t = Template('{% load i18n %}{% trans "May" context message_context %}')
            rendered = t.render(Context({'message_context': 'verb'}))
            self.assertEqual(rendered, 'Kann')

            # Using a filter
            t = Template('{% load i18n %}{% trans "May" context message_context|lower %}')
            rendered = t.render(Context({'message_context': 'MONTH NAME'}))
            self.assertEqual(rendered, 'Mai')
            t = Template('{% load i18n %}{% trans "May" context message_context|lower %}')
            rendered = t.render(Context({'message_context': 'VERB'}))
            self.assertEqual(rendered, 'Kann')

            # Using 'as'
            t = Template('{% load i18n %}{% trans "May" context "month name" as var %}Value: {{ var }}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Value: Mai')
            t = Template('{% load i18n %}{% trans "May" as var context "verb" %}Value: {{ var }}')
            rendered = t.render(Context())
            self.assertEqual(rendered, 'Value: Kann') 
开发者ID:nesdis,项目名称:djongo,代码行数:43,代码来源:test_trans.py


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