Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 June 21, 2010 14:17:22

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

escapejs inside {% trans %}


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

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 21, 2010 14:19:19

Tom E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

escapejs inside {% trans %}


On Mon, Jun 21, 2010 at 2:17 PM, donato.gr <donato...@gmail.com> wrote:
> 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
>

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

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

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 22, 2010 12:34:18

d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

escapejs inside {% trans %}


Thanks,
I'll try it!

On 21 Giu, 15:19, Tom Evans <tevans...@googlemail.com> wrote:
> On Mon, Jun 21, 2010 at 2:17 PM, donato.gr <donato...@gmail.com> wrote:
> > 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
>
> Yes, instead of using {% trans "foo" %}, you can use this alternative
> form, for use inside an output tag:
>
> {{ _("foo")|escapejs }}
>
> Cheers
>
> Tom

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support