'{% trans %} takes message contexts into account (#14806).'

@override_settings(LOCALE_PATHS=extended_locale_paths)
def test_template_tags_pgettext(self):

    trans_real._active = local()
    trans_real._translations = {}
    with translation.override('de'):
        t = Template('{%    load    i18n    %}{%    trans    "May"    context    "nonexistent"    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, 'May')
        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')
        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')
        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')
        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')
