Opened 15 years ago
Closed 15 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: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
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 settings.py ugettext = lambda s: s LANGUAGES = ( ('et', ugettext('Estonian')), ('en', ugettext('English')), $ grep LANGUAGE_CODE settings.py LANGUAGE_CODE = 'et' $ locale LANG=en_US.UTF-8 $ ./manage.py 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. (InteractiveConsole) >>> from django.utils.translation import get_language >>> get_language() 'en-us'
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 by , 15 years ago
Component: | Uncategorized → Internationalization |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
Version: | 1.1 → SVN |
comment:2 by , 15 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Dupe of #9340.