Opened 17 years ago
Closed 11 years ago
#5849 closed New feature (fixed)
Strip indentation and leading/trailing spaces/linebreaks from contents of blocktrans block.
Reported by: | Owned by: | Bouke Haarsma | |
---|---|---|---|
Component: | Internationalization | Version: | dev |
Severity: | Normal | Keywords: | blocktrans strip indentation |
Cc: | chris@…, phartig@…, macek@…, Danilo Bargen, bbr@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The idea is to strip whitespace indentation from the contents of the blocktrans tag, as well as leading and trailing whitespace and linebreaks.
Blocktrans tags allow you to split your translation strings onto multiple lines and this is a good feature, especially if using the "plural" mode.
Picture this:
{% blocktrans number as count %} There is {{count}} message waiting for you {% plural %} There are {{count}} messages waiting for you {% endblocktrans %}
The biggest issue is if you indent the above block. Suddenly those msgids are obsolete and you need to edit all your language files....
Indentation is often changed in HTML since you might nest that block in a new DIV element or whatnot, and the ability to spread the msgids along many lines makes for cleaner looking code.
Furthermore, the current blocktrans tag implementation generates some ugly translation strings when using make-messages if you have indented your msgid block.
Since most HTML is somehow indented, the above can easily look like this:
msgid "\n" "\t\t\t\t\tThere are %(count)s messages\n" "\t\t\t\t\twaiting for you\n" "\t\t\t\t\t"
Note the last line of tabs, since it includes the indentation of the "endblocktrans" tag as well.
See this thread for more:
http://groups.google.com/group/django-developers/browse_thread/thread/60f0a0ac2347c5f5
Attachments (3)
Change History (17)
by , 17 years ago
Attachment: | blocktrans_strip.diff added |
---|
by , 17 years ago
Attachment: | strip_blocktrans_tests.py added |
---|
Some unit tests to show and test outcome of stripping process
comment:1 by , 17 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Accepted, with a possible improvements depending on MT's judgement :)
comment:2 by , 17 years ago
I would like to start by pointing out that as it is right now, the patch breaks a few blocktrans msgids from the admin app.
However I feel that it might be worth it anyway, and I am sure there can be a workaround. Perhaps a transitional period where two checks are made, one with stripping and then a second AS IS if the first fails...
by , 17 years ago
Attachment: | blocktrans_strip.2.diff added |
---|
Original patch could not be applied after rev 6689, this is an update.
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:4 by , 13 years ago
Cc: | added |
---|---|
Easy pickings: | unset |
UI/UX: | unset |
comment:5 by , 13 years ago
I happen to use blocktrans template tag in a non-html template where indentation is important.
What about adding a spaceless_blocktrans block? It would maintain backward compatibility while fixing this issue.
comment:6 by , 13 years ago
Cc: | added |
---|
comment:7 by , 13 years ago
Cc: | added |
---|---|
Component: | Template system → Internationalization |
Type: | Cleanup/optimization → New feature |
I also hate those \t
's and \n
's in blocktrans! When passing PO's to 3rd party translation agencies, they're not always able to handle escapes correctly.
To avoid \t
's and \n
's, I'm forced to have blocktranses on a single line. With plural form and variable interpolation it can easily become 300 chars line!
If we want to stay backwards compatible and not adding any new tag, wouldn't it be possible to add a "trimmed
" option inside the blocktrans option?
Something like: {% blocktrans trimmed ... %
}
It would:
- strip all whitespace from start and end of the string,
- do
s/[\t\n]+/ /g
Just as the browser does.
Thanks for consideration. (I also dare to change the ticket properties.)
comment:8 by , 13 years ago
Cc: | added |
---|
I think both a blocktrans argument or a new tag would be acceptable.
comment:9 by , 12 years ago
Cc: | added |
---|
Replying to Dmitri Fedortchenko <zeraien@…>:
The biggest issue is if you indent the above block. Suddenly those msgids are obsolete and you need to edit all your language files....
Indentation is often changed in HTML since you might nest that block in a new DIV element or whatnot, and the ability to spread the msgids along many lines makes for cleaner looking code.
Another problem that I haven't seen mentioned, that is implied above: The same blocktrans text could be used at different indentation levels and gets interpreted as different msgids, thus needs to be translated more than necessary.
comment:10 by , 12 years ago
Owner: | changed from | to
---|---|
Patch needs improvement: | unset |
Status: | new → assigned |
comment:12 by , 11 years ago
Owner: | changed from | to
---|
Pull request rebased: https://github.com/django/django/pull/1773
comment:13 by , 11 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
RFC as review comments by aaugustin have been solved
comment:14 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Patch that adds stripping of indentation from contents of blocktrans block.