Set Language in the Admin

745 views
Skip to first unread message

Federico Capoano

unread,
Nov 14, 2010, 11:27:23 AM11/14/10
to Django users
Hi guys,

i'm developing an app in 3 languages, en, es and it.

My browser accepts all of them with priority to italian.

Since I've done that the admin started to show up in italian. How can
I force it back to english?

In the setting I put

LANGUAGE_CODE = 'en-gb'

someLiang

unread,
Nov 15, 2010, 10:57:00 PM11/15/10
to django...@googlegroups.com
perhaps you need to comment the statement in your setting.py

'django.middleware.locale.LocaleMiddleware', 



2010/11/15 Federico Capoano <nemesis...@libero.it>

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Rita Liang

someLiang

unread,
Nov 15, 2010, 10:57:46 PM11/15/10
to django...@googlegroups.com
just make it seems like this:

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.locale.LocaleMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

2010/11/16 someLiang <k.canc...@gmail.com>



--
Rita Liang

Federico Capoano

unread,
Nov 16, 2010, 4:58:20 AM11/16/10
to Django users
This will affect the frontend too?


On Nov 16, 4:57 am, someLiang <k.cancer.2...@gmail.com> wrote:
> just make it seems like this:
>
> MIDDLEWARE_CLASSES = (
>     'django.middleware.common.CommonMiddleware',
>     'django.contrib.sessions.middleware.SessionMiddleware',
>     #'django.middleware.locale.LocaleMiddleware',
>     'django.middleware.csrf.CsrfViewMiddleware',
>     'django.contrib.auth.middleware.AuthenticationMiddleware',
>     'django.contrib.messages.middleware.MessageMiddleware',
> )
>
> 2010/11/16 someLiang <k.cancer.2...@gmail.com>
>
>
>
>
>
>
>
>
>
> > perhaps you need to comment the statement in your setting.py
>
> > 'django.middleware.locale.LocaleMiddleware',
>
> > 2010/11/15 Federico Capoano <nemesis.des...@libero.it>
>
> > Hi guys,
>
> >> i'm developing an app in 3 languages, en, es and it.
>
> >> My browser accepts all of them with priority to italian.
>
> >> Since I've done that the admin started to show up in italian. How can
> >> I force it back to english?
>
> >> In the setting I put
>
> >> LANGUAGE_CODE = 'en-gb'
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email to django...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> django-users...@googlegroups.com<django-users%2Bunsubscribe@google groups.com>
> >> .

Tom Evans

unread,
Nov 16, 2010, 5:19:00 AM11/16/10
to django...@googlegroups.com
On Tue, Nov 16, 2010 at 9:58 AM, Federico Capoano
<nemesis...@libero.it> wrote:
> This will affect the frontend too?
>

Yes, I'd replace it with a customized version of the LocaleMiddleware,
something like this ought to do the trick:

from django.middleware.locale import LocaleMiddleware
from django.utils import translation

class LocaleButNotInAdminMiddleware(LocaleMiddleware):
KWARG = 'DisableLocalisation'
def process_view(self, request, view_func, view_args, view_kwargs):
disable_localisation = self.KWARG in view_kwargs and
view_kwargs.pop(self.KWARG)
if disable_localisation:
translation.deactivate()
if hasattr(request, 'LANGUAGE_CODE')
del request.LANGUAGE_CODE
def process_response(self, request, response):
if hasattr(request, 'LANGUAGE_CODE'):
super(LocaleButNotInAdminMiddleware,
self).process_response(request, response)
return response

and then change how you include the admin into your urlconf from
something like this:

urlpatterns = patterns('',
(r'^admin/(.*)', include(admin.site.urls)),
)

to something like this:

urlpatterns = patterns('',
(r'^admin/(.*)', include(admin.site.urls), {'DisableLocalisation': True}),
)

So that it disables the effects of the LocaleMiddleware when the view
to be served will be passed the appropriate kwarg, and the kwarg is
passed to the view by configuring it so in the urlconf. The kwarg
should never make it to the admin views.

Cheers

Tom

Federico Capoano

unread,
Nov 18, 2010, 7:29:36 AM11/18/10
to Django users
Thanks

On Nov 16, 11:19 am, Tom Evans <tevans...@googlemail.com> wrote:
> On Tue, Nov 16, 2010 at 9:58 AM, Federico Capoano
>

Federico Capoano

unread,
Nov 23, 2010, 7:13:17 AM11/23/10
to Django users
I got rid of the LocaleMiddleware.

To translate the frontend of the application I'm using
http://bitbucket.org/carljm/django-localeurl/overview

It seems the best solution for me.
Reply all
Reply to author
Forward
0 new messages