Thursday, October 30, 2014

translation of view messages and business related messages not working

Hi,
  I am using the translation functionality in Django 1.7 successfully for plain strings in a template, so something simple like

{% trans "Edit Client" %}

works just fine.


I am now trying to translate success_message from views with the SuccessMessageMixin and also error messages that bubble up from business logic but I just can't make those work.The messages show up for translation in the .po file. For example:

# python-format
#: views/adminDashboard.py:158
#, python-format
msgid "Productive Unit %(name)s has been created."
msgstr "La Unidad Productiva %(name)s ha sido creada."

I have compiled the messages already.

In my view

....
....
from django.utils.translation import ugettext as _
class CustomerFieldUpdateView(AdminRequiredMixin, SuccessMessageMixin, UpdateView):
    model = Field
    template_name = 'ui/field_update_form.html'
    success_message = _('Productive Unit %(name)s has been updated.')
.....

In the template:
....
{% load i18n %}
....
{% if messages %}
    {% for message in messages %}
              {{ message }}
    {% endfor %}
{% endif %}
....


If I look at self.request.LANGUAGE_CODE in the view is set to 'es' but still the messages that bubble up from python code are displayed in the default ('en') whereas the plain strings in the template are correctly translated to spanish. I also tried using {% trans message.message %} or blocktrans as well, but nothing works.

Any ideas what I am missing?

Thanks!!!
Marcela





--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/be1ce953-ccee-4016-b4d6-686655755986%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment