mirror of
https://github.com/django/django.git
synced 2025-04-21 07:44:36 +00:00
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
This commit is contained in:
parent
1470bb0b23
commit
11e6a88011
@ -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):
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user