language switching in admin

5 views
Skip to first unread message

Kenneth Gonsalves

unread,
Nov 6, 2009, 8:39:53 PM11/6/09
to django...@googlegroups.com
hi,

I have an app in two languages. Until now I was asking the users to change the
language in their browser. I have now implemented setlang in the web
interface, so that they can view in the language of their choice by choosing
the language. I now want to do this in admin - a custom form should do it, but
has anyone done this? Or is it going to come to admin? Or maybe it is there
and I have not noticed it?
--
regards
Kenneth Gonsalves
Senior Project Officer
NRC-FOSS
http://nrcfosshelpline.in/web/

Antoni Aloy

unread,
Nov 7, 2009, 4:49:54 AM11/7/09
to django...@googlegroups.com
2009/11/7 Kenneth Gonsalves <law...@au-kbc.org>:

>
> hi,
>
> I have an app in two languages. Until now I was asking the users to change the
> language in their browser. I have now implemented setlang in the web
> interface, so that they can view in the language of their choice by choosing
> the language. I now want to do this in admin - a custom form should do it, but
> has anyone done this? Or is it going to come to admin? Or maybe it is there
> and I have not noticed it?

And letting the users to change their language modifiying the main
admin template and giving them a change language form?


--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

Frans

unread,
Nov 7, 2009, 5:13:20 AM11/7/09
to Django users
I use the breadcrumbs block in the admin interface to add a link to a
view
using :
(in template)
<div id="breadcrumbs"
<p><span class="breadcrumbs">
<a class="discreet_link" href="{% url content.views.set_language
lang_code="fr" %}">Fr</a>&nbsp;|&nbsp;
<a class="discreet_link" href="{% url content.views.set_language
lang_code="nl" %}">Nl</a>&nbsp;|&nbsp;
<a class="discreet_link" href="{% url content.views.set_language
lang_code="en" %}">En</a>&nbsp;|&nbsp;
<a class="discreet_link" href="{% url content.views.set_language
lang_code="ja" %}"> >日本語</a>&nbsp;
</span></p>
(for each language, in every page, impractical if you have many, but
you can replace that by a special page of links if that's the case
(like google's language switch page) )
</div>

(in url.py)
(r'^lang/(?P<lang_code>[a-zA-Z]+)/$',set_language),


And then I just set the language cookie manually
(in views.py)

def set_language(request,**kwargs):
next = request.REQUEST.get('next', None)
if not next:
next = request.META.get('HTTP_REFERER', None)
if not next:
next = '/'
lang_code = kwargs.get("lang_code",None)
response=HttpResponseRedirect(next)
if lang_code and check_for_language(lang_code):
if hasattr(request, 'session'):
request.session['django_language'] = lang_code
else:
response.set_cookie(settings.LANGUAGE_COOKIE_NAME,
lang_code)
return response

Kenneth Gonsalves

unread,
Nov 7, 2009, 11:17:53 PM11/7/09
to django...@googlegroups.com
On Saturday 07 Nov 2009 3:19:54 pm Antoni Aloy wrote:
> > hi,
> >
> > I have an app in two languages. Until now I was asking the users to
> > change the language in their browser. I have now implemented setlang in
> > the web interface, so that they can view in the language of their choice
> > by choosing the language. I now want to do this in admin - a custom form
> > should do it, but has anyone done this? Or is it going to come to admin?
> > Or maybe it is there and I have not noticed it?
>
> And letting the users to change their language modifiying the main
> admin template and giving them a change language form?
>
well I added the change language form to the main base.html form in admin (by
overriding it), but the call to "/i18n/setlang/" is not working. Maybe a path
problem. Any clues?

Kenneth Gonsalves

unread,
Nov 7, 2009, 11:21:23 PM11/7/09
to django...@googlegroups.com
On Sunday 08 Nov 2009 9:47:53 am Kenneth Gonsalves wrote:
> > And letting the users to change their language modifiying the main
> > admin template and giving them a change language form?
> >
>
> well I added the change language form to the main base.html form in admin
> (by overriding it), but the call to "/i18n/setlang/" is not working.
> Maybe a path problem. Any clues?
>
now it is working - neat ;-)

Kenneth Gonsalves

unread,
Nov 8, 2009, 9:40:50 PM11/8/09
to django...@googlegroups.com
On Sunday 08 Nov 2009 9:51:23 am Kenneth Gonsalves wrote:
> > well I added the change language form to the main base.html form in admin
> > (by overriding it), but the call to "/i18n/setlang/" is not working.
> > Maybe a path problem. Any clues?
> >
>
> now it is working - neat ;-)
>

it was not a path problem, the browser needed to be refreshed to show the
language change

Reply all
Reply to author
Forward
0 new messages