mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
i18n: the i18n tag now supports gettext_noop. unittests updated.
git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@757 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
26bc142f87
commit
2c6e366f0a
@ -290,7 +290,7 @@ class I18NNode(template.Node):
|
|||||||
|
|
||||||
def __init__(self, cmd):
|
def __init__(self, cmd):
|
||||||
self.cmd = 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*$''')
|
self.ngettext_re = re.compile(r'''^\s*ngettext\(((?:".+")|(?:'.+')|(?:""".+"""))\s*,\s*((?:".+")|(?:'.+')|(?:""".+"""))\s*,\s*(.*)\)\s*$''')
|
||||||
|
|
||||||
def _resolve_var(self, s, context):
|
def _resolve_var(self, s, context):
|
||||||
@ -307,8 +307,14 @@ class I18NNode(template.Node):
|
|||||||
def render(self, context):
|
def render(self, context):
|
||||||
m = self.i18n_re.match(self.cmd)
|
m = self.i18n_re.match(self.cmd)
|
||||||
if m:
|
if m:
|
||||||
s = self._resolve_var(m.group(1), context)
|
f = m.group(1)
|
||||||
return translation.gettext(s) % context
|
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)
|
m = self.ngettext_re.match(self.cmd)
|
||||||
if m:
|
if m:
|
||||||
singular = self._resolve_var(m.group(1), context)
|
singular = self._resolve_var(m.group(1), context)
|
||||||
|
@ -238,6 +238,9 @@ TEMPLATE_TESTS = {
|
|||||||
|
|
||||||
# translation of plural form
|
# translation of plural form
|
||||||
'i18n09': ('{% i18n ngettext("singular", "plural", count) %}', {'count': 2}, "plural"),
|
'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.
|
# This replaces the standard template_loader.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user