Translation catalog for localflavor must be loaded manually

32 views
Skip to first unread message

Fidel Ramos

unread,
Apr 14, 2011, 6:51:53 AM4/14/11
to Django developers
I included some fields from localflavor.es.forms in a project, and
expected the error messages to appear translated, as localflavor
already has a catalog. However the messages only appeared in English.

Turns out the localflavor catalog is not automatically loaded, it must
be included manually in the LOCALE_PATHS setting as implied by the
internationalization documentation [1], because only the django/conf/
locale catalog is loaded automatically.

The code snippet for settings.py is simple enough:

import django
import os

DJANGO_BASEDIR = os.path.dirname(django.__file__)

LOCALE_PATHS = (
os.path.join(DJANGO_BASEDIR, 'contrib', 'localflavor',
'locale'),
)

I think this is acceptable, but should at least be documented in a
section in the localflavor documentation [2]. Another possibility
would be tweaking the code to make sure that the localflavor catalog
is automatically loaded, but I haven't looked yet into how to do that.

What solution would be better? If there is an easy and clean way to
load the localflavor catalog when required and the USE_I18N settings
is True I think it would be best for users, because it's reasonable to
expect Django catalogs to be loaded automatically.

Either way once a decision is reached I volunteer to open a ticket and
submit a patch.

[1] http://docs.djangoproject.com/en/1.3/howto/i18n/#using-translations-in-your-own-projects
[2] http://docs.djangoproject.com/en/1.3/ref/contrib/localflavor/

Ramiro Morales

unread,
Apr 14, 2011, 7:52:29 AM4/14/11
to django-d...@googlegroups.com
On Thu, Apr 14, 2011 at 7:51 AM, Fidel Ramos <fidel...@gmail.com> wrote:
> I included some fields from localflavor.es.forms in a project, and
> expected the error messages to appear translated, as localflavor
> already has a catalog. However the messages only appeared in English.
>
> Turns out the localflavor catalog is not automatically loaded, it must
> be included manually in the LOCALE_PATHS setting as implied by the
> internationalization documentation [1], because only the django/conf/
> locale catalog is loaded automatically.

Do you have django.contrib.localflavor listed in your INSTALLED_APPS
setting?.

--
Ramiro Morales

Fidel Ramos

unread,
Apr 14, 2011, 9:36:11 AM4/14/11
to Django developers
On Apr 14, 1:52 pm, Ramiro Morales <cra...@gmail.com> wrote:
> On Thu, Apr 14, 2011 at 7:51 AM, Fidel Ramos <fidelra...@gmail.com> wrote:
> > I included some fields from localflavor.es.forms in a project, and
> > expected the error messages to appear translated, as localflavor
> > already has a catalog. However the messages only appeared in English.
>
> > Turns out the localflavor catalog is not automatically loaded, it must
> > be included manually in the LOCALE_PATHS setting as implied by the
> > internationalization documentation [1], because only the django/conf/
> > locale catalog is loaded automatically.
>
> Do you have django.contrib.localflavor listed in your INSTALLED_APPS
> setting?.

No, I did not. But you're right, including localflavor in
INSTALLED_APPS works as intended and is obviously the best solution.
Thanks, Ramiro.

I still feel this deserves a note in localflavor's documentation, I
want to think I won't be the only person to ever fall in this silly
mistake.

Jannis Leidel

unread,
Apr 14, 2011, 9:51:33 AM4/14/11
to django-d...@googlegroups.com

Yeah, please open a ticket, this is defintiely something we need to document since the behaviour changed in 1.3.

Jannis

Fidel Ramos

unread,
Apr 14, 2011, 12:27:13 PM4/14/11
to Django developers
On Apr 14, 3:51 pm, Jannis Leidel <lei...@gmail.com> wrote:
> Yeah, please open a ticket, this is defintiely something we need to document since the behaviour changed in 1.3.

I opened #15830 (http://code.djangoproject.com/ticket/15830).

Thanks Jannis.
Reply all
Reply to author
Forward
0 new messages