summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorBouke Haarsma <bouke@webatoom.nl>2013-11-08 15:44:37 +0100
committerRamiro Morales <cramm0@gmail.com>2013-12-04 08:36:20 -0300
commit91c38ce4b236e6eeb5f6f636250df7316fa766bd (patch)
treea029d43895ff01137358d2ba47e65dc0b2b6e0a9 /django/utils
parent4d738fcc3bad4e13c3667646a86f9a17603b7d23 (diff)
Fixed 21406 -- Made blocktrans 'trimmed' option preserve line numbers.
Thanks Bouke Haarsma for report, fix and initial patch.
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/translation/trans_real.py31
1 files changed, 18 insertions, 13 deletions
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 9dfac47381..e547800b92 100644
--- a/django/utils/translation/trans_real.py
+++ b/django/utils/translation/trans_real.py
@@ -564,6 +564,12 @@ def templatize(src, origin=None):
lineno_comment_map = {}
comment_lineno_cache = None
+ def join_tokens(tokens, trim=False):
+ message = ''.join(tokens)
+ if trim:
+ message = trim_whitespace(message)
+ return message
+
for t in Lexer(src, origin).tokenize():
if incomment:
if t.token_type == TOKEN_BLOCK and t.contents == 'endcomment':
@@ -586,29 +592,28 @@ def templatize(src, origin=None):
endbmatch = endblock_re.match(t.contents)
pluralmatch = plural_re.match(t.contents)
if endbmatch:
- if trimmed:
- singular = trim_whitespace(''.join(singular))
- else:
- singular = ''.join(singular)
-
if inplural:
- if trimmed:
- plural = trim_whitespace(''.join(plural))
- else:
- plural = ''.join(plural)
if message_context:
- out.write(' npgettext(%r, %r, %r,count) ' % (message_context, singular, plural))
+ out.write(' npgettext(%r, %r, %r,count) ' % (
+ message_context,
+ join_tokens(singular, trimmed),
+ join_tokens(plural, trimmed)))
else:
- out.write(' ngettext(%r, %r, count) ' % (singular, plural))
+ out.write(' ngettext(%r, %r, count) ' % (
+ join_tokens(singular, trimmed),
+ join_tokens(plural, trimmed)))
for part in singular:
out.write(blankout(part, 'S'))
for part in plural:
out.write(blankout(part, 'P'))
else:
if message_context:
- out.write(' pgettext(%r, %r) ' % (message_context, singular))
+ out.write(' pgettext(%r, %r) ' % (
+ message_context,
+ join_tokens(singular, trimmed)))
else:
- out.write(' gettext(%r) ' % singular)
+ out.write(' gettext(%r) ' % join_tokens(singular,
+ trimmed))
for part in singular:
out.write(blankout(part, 'S'))
message_context = None