Django

Code

Changeset 1065

Show
Ignore:
Timestamp:
11/03/05 10:50:41 (3 years ago)
Author:
hugo
Message:

i18n: readded constant string translations, needed for template tags with string constants

Files:

Legend:

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

    r1061 r1065  
    349349        # First read the variable part - decide on wether we need 
    350350        # to parse a string or a variable by peeking into the stream 
    351         if self.peek_char() in ('"', "'"): 
     351        if self.peek_char() in ('_', '"', "'"): 
    352352            self.var = self.read_constant_string_token() 
    353353        else: 
     
    383383        val = '' 
    384384        qchar = None 
     385        i18n = False 
    385386        self.next_char() 
     387        if self.current == '_': 
     388            i18n = True 
     389            self.next_char()  
     390            if self.current != '(': 
     391                raise TemplateSyntaxError, "Bad character (expecting '(') '%s'" % self.current 
     392            self.next_char() 
    386393        if not self.current in ('"', "'"): 
    387394            raise TemplateSyntaxError, "Bad character (expecting '\"' or ''') '%s'" % self.current 
     
    395402        val += self.current 
    396403        self.next_char() 
     404        if i18n: 
     405            if self.current != ')': 
     406                raise TemplateSyntaxError, "Bad character (expecting ')') '%s'" % self.current 
     407            self.next_char() 
     408            val = qchar+_(val.strip(qchar))+qchar 
    397409        return val 
    398410 
  • django/branches/i18n/tests/othertests/templates.py

    r1064 r1065  
    253253    # usage of the get_available_languages tag 
    254254    'i18n12': ('{% load i18n %}{% get_available_languages as langs %}{% for lang in langs %}{% ifequal lang.0 "de" %}{{ lang.0 }}{% endifequal %}{% endfor %}', {}, 'de'), 
     255 
     256    # translation of a constant string 
     257    'i18n13': ('{{ _("Page not found") }}', {'LANGUAGE_CODE': 'de'}, 'Seite nicht gefunden'), 
    255258} 
    256259