Django translations not showing from app's po

1.1k views Asked by At

I've been developing an application which works in English or French (Canadian). Django settings are;

LANGUAGE_CODE = 'en'

LANGUAGES = [
    ('en', gettext('English')),
    ('fr-ca', gettext('Canadian French')),
]
LOCALE_PATHS = (
    ...
    os.path.join(PROJECT_ROOT, 'console', 'locale'),
    ...
)

The app's locale path is console/locale/fr-CA/LC_MESSAGES/

The app however has recently stopped rendering the vast majority of the translations, while django debug toolbar, and other apps are displaying French without issue.

For example, I've got a form with 'First name', 'Last name', 'Email'. Yesterday this was correctly using the po file;

#: console/forms/participants.py:631
msgid "First Name"
msgstr "Prénom"

#: console/forms/participants.py:635
msgid "Last Name"
msgstr "Nom"

#: console/forms/participants.py:140 console/forms/participants.py:469
#: console/forms/participants.py:639 console/models/mixins.py:70
msgid "Email"
msgstr "Courriel"

But today, only the Email string is appearing in French. I assume ugettext is getting that from another application because I've tested it in the shell;

>>> from django.utils.translation import ugettext, activate
>>> activate('fr-ca')
>>> ugettext('Sunday')
u'dimanche'
>>> ugettext('Event')
u'Event'
>>> ugettext('Yes')
u'Oui'
>>> ugettext('Gender')
u'Gender'
>>> ugettext('enquiry')
u'enquiry'
>>> ugettext('Enquiry')
u'Enquiry'
>>> ugettext('Receive notifications about other events.')
u'Receive notifications about other events.'

These are all taken from the app's po file;

#: console/models/events.py:35 console/models/events.py:206
#: console/models/participants.py:81 console/models/vouchers.py:14
msgid "Event"
msgstr "Événement"

#: console/models/participants.py:113
msgid "Gender"
msgstr "Sexe"

#: console/models/participants.py:160
msgid "Receive notifications about other events."
msgstr "Recevez des notifications pour un événement."

It goes without saying I've ran the translation management commands (and can see the locale paths being output);

manage.py makemessages -l fr-CA
manage.py compilemessages -l fr-CA
1

There are 1 answers

1
Artem Bernatskyi On
  • You should remember that ugettext_lazy is a lazy evaluation and should be used in models and forms (as they load only once in Django) for views you should use gettext
  • Try delete (backup) translation files and recreate them again
  • Check templates for existence of translation blocks