mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +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):
|
||||
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)
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user