try this
def set_language(request, lang_code):
next = request.REQUEST.get('next', None)
if not next:
next = '/'
response = http.HttpResponseRedirect(next)
if lang_code and check_for_language(lang_code):
settings.LANGUAGE_CODE=lang_code
return response
On Oct 12, 6:12 am, Chuck22 <[EMAIL PROTECTED]> wrote:
> thanks Satheesh, the set_language function is partially working for
> me. When I click the lauguage hyperlinks, only the word "Home" works,
> but when I change the msgid to be "Home1", it stop working. It seems
> that "Home" is a django preserved word which get auto-translated.
>
> 1. In my base.html, I have
>
> {% load i18n %}
>
> {% trans "Home1" %}
>
> 2. django.po and django.mo files are generated correctly for the
> lauguages.
>
> msgid "Home1"
> msgstr "My_Translation"
>
> 3. In my settings.py, I have
>
> USE_I18N = True
>
> LANGUAGE_CODE = 'en-us'
>
> MIDDLEWARE_CLASSES = (
> 'django.middleware.common.CommonMiddleware',
> 'django.contrib.sessions.middleware.SessionMiddleware',
> 'django.middleware.locale.LocaleMiddleware',
> 'django.contrib.auth.middleware.AuthenticationMiddleware',
> )
>
> 4. syncdb is done, and session table is generated.
>
> 5. language preferrence selection is like the code below.
>
> I don't know which piece is missing. Anyone can suggest? Thanks.
>
> On Oct 10, 1:11 am, cschand <[EMAIL PROTECTED]> wrote:
>
> > Even then you want in get method you can use the below code.
>
> > In view
>
> > from django import http
> > from django.utils.translation import check_for_language
> > from django.conf import settings
>
> > def set_language(request, lang_code):
> > """
> > Patched for Get method
> > """
> > next = request.REQUEST.get('next', None)
> > if not next:
> > next = '/'
> > response = http.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
>
> > And in template
> > <ul class="language_holder">
>
> > {% for lang in LANGUAGES %}
>
> > <a href="/setlang/{{ lang.0 }}/">{{ lang.1 }}</a>
>
> > {% endfor %}
>
> > </ul>
>
> > in urls
> > url(r'^setlang/(?P<lang_code>.*)/$', 'utils.views.set_language')
>
> > I dont know it is a good practice to do
>
> > Satheesh
>
> > On Oct 10, 9:30 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> > wrote:
>
> > > On Thu, 2008-10-09 at 23:51 -0400, Chuck Bai2 wrote:
> > > > I want to allow user select language preference through clicking the
> > > > language hyperlinks like "_English_ | _French_" switch. And I also want
> > > > to redirect back to the previous page after clicking the language
> > > > switch. Is it possible to use Django view:
> > > > django.views.i18n.set_language? In the documentation, there is an
> > > > example using form submit to select language using this view.
>
> > > > <form action="/i18n/setlang/" method="post">
> > > > <input name="next" type="hidden" value="/next/page/" />
> > > > <select name="language">
> > > > {% for lang in LANGUAGES %}
> > > > <option value="{{ lang.0 }}">{{ lang.1 }}</option>
> > > > {% endfor %}
> > > > </select>
> > > > <input type="submit" value="Go" />
> > > > </form>
>
> > > > But I want to implement this using hyperlinks and want to know how.
>
> > > You'll need to write your own view to handle this (you could look at
> > > Django's view for inspiration). Django intentionally doesn't support
> > > this because it's bad practice (using a GET request to initiate a state
> > > change).
>
> > > Regards,
> > > Malcolm- Hide quoted text -
>
> > - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---