Django

Code

Changeset 757

Show
Ignore:
Timestamp:
10/01/05 08:05:57 (3 years ago)
Author:
hugo
Message:

i18n: the i18n tag now supports gettext_noop. unittests updated.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/i18n/django/core/defaulttags.py

    r755 r757  
    291291    def __init__(self, cmd): 
    292292        self.cmd = cmd 
    293         self.i18n_re = re.compile(r'^\s*_\((.*)\)\s*$') 
     293        self.i18n_re = re.compile(r'^\s*(_|gettext|gettext_noop)\((.*)\)\s*$') 
    294294        self.ngettext_re = re.compile(r'''^\s*ngettext\(((?:".+")|(?:'.+')|(?:""".+"""))\s*,\s*((?:".+")|(?:'.+')|(?:""".+"""))\s*,\s*(.*)\)\s*$''') 
    295295 
     
    308308        m = self.i18n_re.match(self.cmd) 
    309309        if m: 
    310             s = self._resolve_var(m.group(1), context) 
    311             return translation.gettext(s) % context 
     310            f = m.group(1) 
     311            s = self._resolve_var(m.group(2), context) 
     312            if f in ('_', 'gettext'): 
     313                return translation.gettext(s) % context 
     314            elif f == 'gettext_noop': 
     315                return translation.gettext_noop(s) % context 
     316            else: 
     317                raise template.TemplateSyntaxError("i18n only supports _, gettext, gettext_noop and ngettext as functions, not %s" % f) 
    312318        m = self.ngettext_re.match(self.cmd) 
    313319        if m: 
  • django/branches/i18n/tests/othertests/templates.py

    r755 r757  
    239239    # translation of plural form 
    240240    'i18n09': ('{% i18n ngettext("singular", "plural", count) %}', {'count': 2}, "plural"), 
     241 
     242    # simple non-translation (only marking) of a string to german 
     243    'i18n10': ('{% i18n gettext_noop("Page not found") %}', {'LANGUAGE_CODE': 'de'}, "Page not found"), 
    241244} 
    242245