diff --git a/django/core/defaulttags.py b/django/core/defaulttags.py index 4e1b4e551c..5898352a10 100644 --- a/django/core/defaulttags.py +++ b/django/core/defaulttags.py @@ -290,7 +290,7 @@ class I18NNode(template.Node): def __init__(self, cmd): self.cmd = cmd - self.i18n_re = re.compile(r'^\s*_\((.*)\)\s*$') + self.i18n_re = re.compile(r'^\s*(_|gettext|gettext_noop)\((.*)\)\s*$') self.ngettext_re = re.compile(r'''^\s*ngettext\(((?:".+")|(?:'.+')|(?:""".+"""))\s*,\s*((?:".+")|(?:'.+')|(?:""".+"""))\s*,\s*(.*)\)\s*$''') def _resolve_var(self, s, context): @@ -307,8 +307,14 @@ class I18NNode(template.Node): def render(self, context): m = self.i18n_re.match(self.cmd) if m: - s = self._resolve_var(m.group(1), context) - return translation.gettext(s) % context + f = m.group(1) + s = self._resolve_var(m.group(2), context) + if f in ('_', 'gettext'): + return translation.gettext(s) % context + elif f == 'gettext_noop': + return translation.gettext_noop(s) % context + else: + raise template.TemplateSyntaxError("i18n only supports _, gettext, gettext_noop and ngettext as functions, not %s" % f) m = self.ngettext_re.match(self.cmd) if m: singular = self._resolve_var(m.group(1), context) diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py index f848863f4b..0204303bbd 100644 --- a/tests/othertests/templates.py +++ b/tests/othertests/templates.py @@ -238,6 +238,9 @@ TEMPLATE_TESTS = { # translation of plural form 'i18n09': ('{% i18n ngettext("singular", "plural", count) %}', {'count': 2}, "plural"), + + # simple non-translation (only marking) of a string to german + 'i18n10': ('{% i18n gettext_noop("Page not found") %}', {'LANGUAGE_CODE': 'de'}, "Page not found"), } # This replaces the standard template_loader.