Opened 9 years ago

Closed 9 years ago

#11648 closed (duplicate)

translation.get_language() should remove sublanguage code if it is not in settings.LANGUAGES

Reported by: mrts Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


When translation.get_language_from_request() processes the Accept-Language HTTP header it makes sure to remove the sublanguage code if it is not in settings.LANGUAGES, so that translation.get_language() subsequently returns only the "main" language code.

However, the behaviour is different in shell:

$ grep -2 LANGUAGES

ugettext = lambda s: s
    ('et', ugettext('Estonian')),
    ('en', ugettext('English')),


$ locale

$ ./ shell --plain
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.utils.translation import get_language
>>> get_language()

I.e. the shell locale is used unchanged.

That breaks code that assumes translation.get_language_from_request() behaviour, e.g. auto-translated model fields (properties that return getattr(self, fieldname + langcode) where langcode comes from get_language()).

This is a minor inconsistency easily fixable with translation.activate() in the shell, so feel free to wontfix this. However, if #9340 gets fixed, perhaps this could be something that can be looked into while at it.

Change History (2)

comment:1 Changed 9 years ago by mrts

Component: UncategorizedInternationalization
Triage Stage: UnreviewedDesign decision needed
Version: 1.1SVN

comment:2 Changed 9 years ago by Malcolm Tredinnick

Resolution: duplicate
Status: newclosed

Dupe of #9340.

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