On Wed, Dec 14, 2011 at 5:00 PM, kreid <kharronr...@gmail.com> wrote:
> My template file contains javascript/jquery.  When translating with
> gettext from a .js file there are no problems as the 'makemessages'
> switch picks it up and places it into the djangojs.po file.  However,
> when the javascript is embedded in the template file (i.e. a txt file)
> makemessages picks up on 'trans' tags to place in the .po file.  The
> trans tags are not being translated in the javascript...only in the
> html.
>
> What am I doing wrong?
>

I'm sure you've read the docs on JS i18n:

https://docs.djangoproject.com/en/1.3/topics/i18n/internationalization/#specifying-translation-strings-in-javascript-code

In particular, for JS translations, you need to:

* Ensure that the javascript translation catalog is loaded:

  <script type="text/javascript" src="{% url
django.views.i18n.javascript_catalog %}"></script>

* Get your translations out with the gettext() function:

  document.write(gettext('Translate this'));

You don't use the django template tags for translations in javascript
files ({% trans %}/{% blocktrans %}) as these are not rendered
templates but javascript, and will typically not be served at all by
django, but directly by your webserver.

If you are trying to get translations into javascript embedded inside
a django template, you can do so using the {% trans %} tags, but
django does not know the context you are outputting in. Eg this may
cause problems:

<script type='text/javascript'>
var foo = '{% trans "It is me" %}';
</script>

The english translation would work, but the French would end up
rendered like this (note the broken quotation):

<script type='text/javascript'>
var foo = 'C'est moi';
</script>

For this reason, it is better to use the js specific way of accessing
translations.

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-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to