Commits

Anonymous committed d5d260c

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

Comments (0)

Files changed (2)

django/core/template/__init__.py

         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()
         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
            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):

tests/othertests/templates.py

 
     # 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):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.