On Oct 30, 2014 8:45 PM, "Marcela Campo" <marcelacampo@gmail.com> wrote:
>
> 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 _
Try replacing ugettext with ugettext_lazy. Read the relevante documentation for the details.
> 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.
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/CAO7PdF8vJ5fx57V5CqmYqgtz_7Y5V%3DPNV_tx0XzgKBDXcGiMNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment