Opened 13 years ago

Closed 13 years ago

Last modified 7 years ago

#17326 closed Bug (invalid)

{% trans %} in inline javascript code

Reported by: Rémy Hubscher Owned by: nobody
Component: Template system Version: 1.3
Severity: Normal Keywords: translation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

We've got this issue on django-filebrowser but I think it is related to a django template translation problem.

How to escape {% trans %} for js ? Maybe we need a {% transjs %} tag ?

https://github.com/sehmaschine/django-filebrowser/pull/54

Change History (2)

comment:1 by Bas Peschier, 13 years ago

Resolution: invalid
Status: newclosed

If you need specific manipulation of translation results, you can use the new {% trans "my string" as my_variable %} feature as described at https://docs.djangoproject.com/en/dev/topics/i18n/translation/#trans-template-tag

After the translation is available in the context, you can escape it.

comment:2 by Max Arnold, 7 years ago

Another way to solve this:

messages: {
    typeError: '{{ _("{file} has invalid extension. Only {extensions} are allowed.")|escapejs }}'
}

https://stackoverflow.com/questions/7496173/or-trans-in-django-templates

Note: See TracTickets for help on using tickets.
Back to Top