escapejs inside {% trans %}

169 views
Skip to first unread message

donato.gr

unread,
Jun 21, 2010, 9:17:12 AM6/21/10
to Django users
Hi,
I had this code in a template file:
alert('{% trans "a string" %}')

It gave error when translated bacause the translated string had a '
inside. So, I replaced " with ' in the template line and all worked
fine.

To avoid any problem with 'escape chars', is there a way to escape
translated strings, like the 'escapejs' filter tag does?
Something like "{% trans "a string" | escapejs %}"

Thank you

Tom Evans

unread,
Jun 21, 2010, 9:19:09 AM6/21/10
to django...@googlegroups.com

Yes, instead of using {% trans "foo" %}, you can use this alternative
form, for use inside an output tag:

{{ _("foo")|escapejs }}

Cheers

Tom

donato.gr

unread,
Jun 22, 2010, 7:34:13 AM6/22/10
to Django users
Thanks,
I'll try it!

On 21 Giu, 15:19, Tom Evans <tevans...@googlemail.com> wrote:
Reply all
Reply to author
Forward
0 new messages