1
0
mirror of https://github.com/django/django.git synced 2025-07-04 09:49:12 +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:
Georg Bauer 2005-10-01 13:05:57 +00:00
parent 26bc142f87
commit 2c6e366f0a
2 changed files with 12 additions and 3 deletions

View File

@ -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)

View File

@ -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.