Changeset 1066
- Timestamp:
- 11/03/05 11:10:16 (3 years ago)
- Files:
-
- django/branches/i18n/django/utils/translation.py (modified) (3 diffs)
- django/branches/i18n/docs/translation.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/i18n/django/utils/translation.py
r1061 r1066 365 365 endblock_re = re.compile(r"""^\s*endblocktrans$""") 366 366 plural_re = re.compile(r"""^\s*plural$""") 367 constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""") 367 368 def templateize(src): 368 369 from django.core.template import tokenize, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK … … 415 416 imatch = inline_re.match(t.contents) 416 417 bmatch = block_re.match(t.contents) 418 cmatches = constant_re.findall(t.contents) 417 419 if imatch: 418 420 g = imatch.group(1) … … 425 427 singular = [] 426 428 plural = [] 429 elif cmatches: 430 for cmatch in cmatches: 431 out.write(' _(%s) ' % cmatch) 427 432 else: 428 433 out.write(blankout(t.contents, 'B')) 429 434 elif t.token_type == TOKEN_VAR: 430 435 parts = t.contents.split('|') 431 for p in parts: 436 cmatch = constant_re.match(parts[0]) 437 if cmatch: 438 out.write(' _(%s) ' % cmatch.group(1)) 439 for p in parts[1:]: 432 440 if p.find(':_(') >= 0: 433 441 out.write(' %s ' % p.split(':',1)[1]) django/branches/i18n/docs/translation.txt
r1063 r1066 172 172 All tags live in the ``i18n`` tag library, so you need to specify 173 173 ``{% load i18n %}`` in the head of your template to make use of them. 174 175 There are some places where you will encounter constant strings in your template code. 176 One is filter arguments, the other are normal string constants for tags. If you need to 177 translate those, you can use the ``_("....")`` syntax:: 178 179 {% some_special_tag _("Page not found") value|yesno:_("yes,no") %} 180 181 In this case both the filter and the tag will see the already translated string, so they 182 don't need to be aware of translations. And both strings will be pulled out of the templates 183 for translation and stored in the .po files. 174 184 175 185 The ``setlang`` redirect view
