Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#11384 closed (fixed)

Django Internationalization override translation mechanisim not working as expected

Reported by: alfredo Owned by: jezdez
Component: Internationalization Version: 1.0
Severity: Keywords: internationalization translation overrride not-working
Cc: alfredo@…, michal@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by ramiro)

The internationalization override is not working as expected

The documentation says:

you can write applications that include their own translations, and you can override base translations in your project path. Or, you can just build a big project out of several apps and put all translations into one big project message file. The choice is yours.

Which makes perfect sense to have distributable apps and be able to override such translations provided with the app

http://docs.djangoproject.com/en/dev/topics/i18n/#using-translations-in-your-own-projects

But having a distributable app with its translation, living outside the project path, lets say:

$VIRTUALENV/$APPPATH/locale/<language>/LC_MESSAGES/django.po
$VIRTUALENV/$APPPATH/locale/<language>/LC_MESSAGES/django.mo

And trying to override such translation with:

$PROJECTPATH/locale/<language>/LC_MESSAGES/django.po
$PROJECTPATH/locale/<language>/LC_MESSAGES/django.mo

It will pick up the translation from the app ignoring the one in the project path.

Looking at the code I can see that the translation on the project path gets to be called first

http://code.djangoproject.com/browser/django/trunk/django/utils/translation/trans_real.py#L176

and then the translations on the external apps which overrides the translations already picked up in the project path.

It looks like the answer would be to load first the translation of the apps and then the translations in the project path. I've tried switching them and it worked for me.

Thank you!

Change History (8)

comment:1 Changed 6 years ago by garcia_marc

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to garcia_marc
  • Patch needs improvement unset

comment:2 Changed 5 years ago by emes

  • Cc michal@… added

This definitely needs to be changed. Project-level translations should be used by default, overriding those distributed with apps.

The solution is to create empty app with translations only, and to put it on the end of INSTALLED_APPS list. This is, however, a bit hacky.

comment:3 Changed 5 years ago by ramiro

  • Description modified (diff)

(reformatted description)

comment:4 Changed 5 years ago by ramiro

#11893 was a duplicate.

comment:5 Changed 5 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:6 Changed 5 years ago by jezdez

  • Owner changed from garcia_marc to jezdez
  • Status changed from new to assigned

comment:7 Changed 5 years ago by jezdez

  • Resolution set to fixed
  • Status changed from assigned to closed

(In [12447]) Fixed #11384 - Make sure translations in the project directory really override translations in apps as specified in the docs.

comment:8 Changed 5 years ago by jezdez

(In [12609]) [1.1.X] Fixed #11384 - Make sure translations in the project directory really override translations in apps as specified in the docs.

Backport of r12447.

Note: See TracTickets for help on using tickets.
Back to Top