I've started using blocktrans in my templates and noticed that when
using make_messages it includes all the tabs and linebreaks around the
text that is surrounded by blocktrans tags.
For example:
{% blocktrans %}
Translate this string
{% plural %}
And this plural string
{% endblocktrans %}
Will turn into:
"\t\t\t\tTranslate this string"
"\t\t"
Plural:
"\t\t"
"\t\t\t\tAnd this plural string"
in the .po file... (it affects both normal blocktrans and plural
blocktrans)
This is rather ugly i think. Also in HTML, indentation and linebreaks
are generally ignored, so in that sense django does not behave
correctly. If you have a string of some length you might not want to
place it all on the same line, for the beauty of the syntax...
So I put in some preliminary work for stripping the translation
string.
I just realised that my patch only strips the ends of the string which
still leaves the middle full of ugliness if you have a multiline
msgid.
Has this ever been discussed?
To what extent would the stripping be appropriate? Or perhaps there is
a simpler solution that I am missing?
Index: django/templatetags/i18n.py
===================================================================
--- django/templatetags/i18n.py (revision 6603)
+++ django/templatetags/i18n.py (working copy)
@@ -66,10 +66,12 @@
for var,val in self.extra_context.items():
context[var] = val.resolve(context)
singular = self.render_token_list(self.singular)
+ singular = singular.strip()
if self.plural and self.countervar and self.counter:
count = self.counter.resolve(context)
context[self.countervar] = count
plural = self.render_token_list(self.plural)
+ plural = plural.strip()
result = translation.ungettext(singular, plural, count)
else:
result = translation.ugettext(singular)
Index: django/utils/translation/trans_real.py
===================================================================
--- django/utils/translation/trans_real.py (revision 6603)
+++ django/utils/translation/trans_real.py (working copy)
@@ -442,13 +442,13 @@
pluralmatch = plural_re.match(t.contents)
if endbmatch:
if inplural:
- out.write(' ngettext(%r,%r,count) ' %
(''.join(singular), ''.join(plural)))
+ out.write(' ngettext(%r,%r,count) ' %
(''.join(singular).strip(), ''.join(plural).strip()))
for part in singular:
out.write(blankout(part, 'S'))
for part in plural:
out.write(blankout(part, 'P'))
else:
- out.write(' gettext(%r) ' %
''.join(singular))
+ out.write(' gettext(%r) ' %
''.join(singular).strip())
for part in singular:
out.write(blankout(part, 'S'))
intrans = False
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---