mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
i18n: fixed documentation and message scanner for constant string translations
git-svn-id: http://code.djangoproject.com/svn/django/branches/i18n@1066 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
11e6a88011
commit
9e724c2523
@ -364,6 +364,7 @@ inline_re = re.compile(r"""^\s*trans\s+((?:".*?")|(?:'.*?'))\s*""")
|
|||||||
block_re = re.compile(r"""^\s*blocktrans(?:\s+|$)""")
|
block_re = re.compile(r"""^\s*blocktrans(?:\s+|$)""")
|
||||||
endblock_re = re.compile(r"""^\s*endblocktrans$""")
|
endblock_re = re.compile(r"""^\s*endblocktrans$""")
|
||||||
plural_re = re.compile(r"""^\s*plural$""")
|
plural_re = re.compile(r"""^\s*plural$""")
|
||||||
|
constant_re = re.compile(r"""_\(((?:".*?")|(?:'.*?'))\)""")
|
||||||
def templateize(src):
|
def templateize(src):
|
||||||
from django.core.template import tokenize, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
|
from django.core.template import tokenize, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK
|
||||||
"""
|
"""
|
||||||
@ -414,6 +415,7 @@ def templateize(src):
|
|||||||
if t.token_type == TOKEN_BLOCK:
|
if t.token_type == TOKEN_BLOCK:
|
||||||
imatch = inline_re.match(t.contents)
|
imatch = inline_re.match(t.contents)
|
||||||
bmatch = block_re.match(t.contents)
|
bmatch = block_re.match(t.contents)
|
||||||
|
cmatches = constant_re.findall(t.contents)
|
||||||
if imatch:
|
if imatch:
|
||||||
g = imatch.group(1)
|
g = imatch.group(1)
|
||||||
if g[0] == '"': g = g.strip('"')
|
if g[0] == '"': g = g.strip('"')
|
||||||
@ -424,11 +426,17 @@ def templateize(src):
|
|||||||
inplural = False
|
inplural = False
|
||||||
singular = []
|
singular = []
|
||||||
plural = []
|
plural = []
|
||||||
|
elif cmatches:
|
||||||
|
for cmatch in cmatches:
|
||||||
|
out.write(' _(%s) ' % cmatch)
|
||||||
else:
|
else:
|
||||||
out.write(blankout(t.contents, 'B'))
|
out.write(blankout(t.contents, 'B'))
|
||||||
elif t.token_type == TOKEN_VAR:
|
elif t.token_type == TOKEN_VAR:
|
||||||
parts = t.contents.split('|')
|
parts = t.contents.split('|')
|
||||||
for p in parts:
|
cmatch = constant_re.match(parts[0])
|
||||||
|
if cmatch:
|
||||||
|
out.write(' _(%s) ' % cmatch.group(1))
|
||||||
|
for p in parts[1:]:
|
||||||
if p.find(':_(') >= 0:
|
if p.find(':_(') >= 0:
|
||||||
out.write(' %s ' % p.split(':',1)[1])
|
out.write(' %s ' % p.split(':',1)[1])
|
||||||
else:
|
else:
|
||||||
|
@ -172,6 +172,16 @@ two tags::
|
|||||||
All tags live in the ``i18n`` tag library, so you need to specify
|
All tags live in the ``i18n`` tag library, so you need to specify
|
||||||
``{% load i18n %}`` in the head of your template to make use of them.
|
``{% load i18n %}`` in the head of your template to make use of them.
|
||||||
|
|
||||||
|
There are some places where you will encounter constant strings in your template code.
|
||||||
|
One is filter arguments, the other are normal string constants for tags. If you need to
|
||||||
|
translate those, you can use the ``_("....")`` syntax::
|
||||||
|
|
||||||
|
{% some_special_tag _("Page not found") value|yesno:_("yes,no") %}
|
||||||
|
|
||||||
|
In this case both the filter and the tag will see the already translated string, so they
|
||||||
|
don't need to be aware of translations. And both strings will be pulled out of the templates
|
||||||
|
for translation and stored in the .po files.
|
||||||
|
|
||||||
The ``setlang`` redirect view
|
The ``setlang`` redirect view
|
||||||
-----------------------------
|
-----------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user