diff options
| author | Georg Bauer <gb@hugo.westfalen.de> | 2005-11-03 16:50:41 +0000 |
|---|---|---|
| committer | Georg Bauer <gb@hugo.westfalen.de> | 2005-11-03 16:50:41 +0000 |
| commit | 11e6a880111f60b9d037a4f1f53b7b68d1da552f (patch) | |
| tree | 6de274d9b3d7fc617b0eb4fdfe3b5af042c54d23 | |
| parent | 1470bb0b2391028e00ea1eb95eca7c90e12b004c (diff) | |
i18n: readded constant string translations, needed for template tags with string constants
git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@1065 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/template/__init__.py | 14 | ||||
| -rw-r--r-- | tests/othertests/templates.py | 3 |
2 files changed, 16 insertions, 1 deletions
diff --git a/django/core/template/__init__.py b/django/core/template/__init__.py index 0011cb2c9a..2f1caf657f 100644 --- a/django/core/template/__init__.py +++ b/django/core/template/__init__.py @@ -348,7 +348,7 @@ class FilterParser: self.current_filter_arg = None # First read the variable part - decide on wether we need # to parse a string or a variable by peeking into the stream - if self.peek_char() in ('"', "'"): + if self.peek_char() in ('_', '"', "'"): self.var = self.read_constant_string_token() else: self.var = self.read_alphanumeric_token() @@ -382,7 +382,14 @@ class FilterParser: or ' characters. The string is returned with it's delimiters.""" val = '' qchar = None + i18n = False self.next_char() + if self.current == '_': + i18n = True + self.next_char() + if self.current != '(': + raise TemplateSyntaxError, "Bad character (expecting '(') '%s'" % self.current + self.next_char() if not self.current in ('"', "'"): raise TemplateSyntaxError, "Bad character (expecting '\"' or ''') '%s'" % self.current qchar = self.current @@ -394,6 +401,11 @@ class FilterParser: val += self.current val += self.current self.next_char() + if i18n: + if self.current != ')': + raise TemplateSyntaxError, "Bad character (expecting ')') '%s'" % self.current + self.next_char() + val = qchar+_(val.strip(qchar))+qchar return val def read_alphanumeric_token(self): diff --git a/tests/othertests/templates.py b/tests/othertests/templates.py index c889f2c7cb..ec6c55fb05 100644 --- a/tests/othertests/templates.py +++ b/tests/othertests/templates.py @@ -252,6 +252,9 @@ TEMPLATE_TESTS = { # usage of the get_available_languages tag 'i18n12': ('{% load i18n %}{% get_available_languages as langs %}{% for lang in langs %}{% ifequal lang.0 "de" %}{{ lang.0 }}{% endifequal %}{% endfor %}', {}, 'de'), + + # translation of a constant string + 'i18n13': ('{{ _("Page not found") }}', {'LANGUAGE_CODE': 'de'}, 'Seite nicht gefunden'), } def test_template_loader(template_name, template_dirs=None): |
