'Ensure that message contexts are taken into account the {% trans %} and
{% blocktrans %} template tags.
Refs #14806.'

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

    trans_real._active = local()
    trans_real._translations = {}
    with translation.override(u'de'):
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    "unexisting"    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'May')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    "month    name"    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Mai')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    "verb"    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Kann')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    message_context    %}')
        rendered = t.render(Context({u'message_context': u'month    name'}))
        self.assertEqual(rendered, u'Mai')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    message_context    %}')
        rendered = t.render(Context({u'message_context': u'verb'}))
        self.assertEqual(rendered, u'Kann')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    message_context|lower    %}')
        rendered = t.render(Context({u'message_context': u'MONTH    NAME'}))
        self.assertEqual(rendered, u'Mai')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    message_context|lower    %}')
        rendered = t.render(Context({u'message_context': u'VERB'}))
        self.assertEqual(rendered, u'Kann')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    context    "month    name"    as    var    %}Value:    {{    var    }}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Value:    Mai')
        t = Template(u'{%    load    i18n    %}{%    trans    "May"    as    var    context    "verb"    %}Value:    {{    var    }}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Value:    Kann')
        self.assertRaises(TemplateSyntaxError, Template, u'{%    load    i18n    %}{%    trans    "May"    context    as    var    %}{{    var    }}')
        self.assertRaises(TemplateSyntaxError, Template, u'{%    load    i18n    %}{%    trans    "May"    as    var    context    %}{{    var    }}')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    "unexisting"    %}May{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'May')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    "month    name"    %}May{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Mai')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    "verb"    %}May{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Kann')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    message_context    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({u'message_context': u'month    name'}))
        self.assertEqual(rendered, u'Mai')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    message_context    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({u'message_context': u'verb'}))
        self.assertEqual(rendered, u'Kann')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    message_context|lower    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({u'message_context': u'MONTH    NAME'}))
        self.assertEqual(rendered, u'Mai')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    message_context|lower    %}May{%    endblocktrans    %}')
        rendered = t.render(Context({u'message_context': u'VERB'}))
        self.assertEqual(rendered, u'Kann')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    count    number=1    context    "super    search"    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'1    Super-Ergebnis')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    count    number=2    context    "super    search"    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'2    Super-Ergebnisse')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    "other    super    search"    count    number=1    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'1    anderen    Super-Ergebnis')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    context    "other    super    search"    count    number=2    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'2    andere    Super-Ergebnisse')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    with    num_comments=5    context    "comment    count"    %}There    are    {{    num_comments    }}    comments{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Es    gibt    5    Kommentare')
        t = Template(u'{%    load    i18n    %}{%    blocktrans    with    num_comments=5    context    "other    comment    count"    %}There    are    {{    num_comments    }}    comments{%    endblocktrans    %}')
        rendered = t.render(Context())
        self.assertEqual(rendered, u'Andere:    Es    gibt    5    Kommentare')
        self.assertRaises(TemplateSyntaxError, Template, u'{%    load    i18n    %}{%    blocktrans    context    with    month="May"    %}{{    month    }}{%    endblocktrans    %}')
        self.assertRaises(TemplateSyntaxError, Template, u'{%    load    i18n    %}{%    blocktrans    context    %}{%    endblocktrans    %}')
        self.assertRaises(TemplateSyntaxError, Template, u'{%    load    i18n    %}{%    blocktrans    count    number=2    context    %}{{    number    }}    super    result{%    plural    %}{{    number    }}    super    results{%    endblocktrans    %}')
