root / ui / i18n.py @ b687587e
History | View | Annotate | Download (2.3 kB)
1 | a5bc3755 | Vangelis Koukis | # Copyright 2011 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | a5bc3755 | Vangelis Koukis | #
|
3 | a5bc3755 | Vangelis Koukis | # Redistribution and use in source and binary forms, with or
|
4 | a5bc3755 | Vangelis Koukis | # without modification, are permitted provided that the following
|
5 | a5bc3755 | Vangelis Koukis | # conditions are met:
|
6 | a5bc3755 | Vangelis Koukis | #
|
7 | a5bc3755 | Vangelis Koukis | # 1. Redistributions of source code must retain the above
|
8 | a5bc3755 | Vangelis Koukis | # copyright notice, this list of conditions and the following
|
9 | a5bc3755 | Vangelis Koukis | # disclaimer.
|
10 | a5bc3755 | Vangelis Koukis | #
|
11 | a5bc3755 | Vangelis Koukis | # 2. Redistributions in binary form must reproduce the above
|
12 | a5bc3755 | Vangelis Koukis | # copyright notice, this list of conditions and the following
|
13 | a5bc3755 | Vangelis Koukis | # disclaimer in the documentation and/or other materials
|
14 | a5bc3755 | Vangelis Koukis | # provided with the distribution.
|
15 | a5bc3755 | Vangelis Koukis | #
|
16 | a5bc3755 | Vangelis Koukis | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | a5bc3755 | Vangelis Koukis | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | a5bc3755 | Vangelis Koukis | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | a5bc3755 | Vangelis Koukis | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | a5bc3755 | Vangelis Koukis | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | a5bc3755 | Vangelis Koukis | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | a5bc3755 | Vangelis Koukis | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | a5bc3755 | Vangelis Koukis | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | a5bc3755 | Vangelis Koukis | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | a5bc3755 | Vangelis Koukis | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | a5bc3755 | Vangelis Koukis | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | a5bc3755 | Vangelis Koukis | # POSSIBILITY OF SUCH DAMAGE.
|
28 | a5bc3755 | Vangelis Koukis | #
|
29 | a5bc3755 | Vangelis Koukis | # The views and conclusions contained in the software and
|
30 | a5bc3755 | Vangelis Koukis | # documentation are those of the authors and should not be
|
31 | a5bc3755 | Vangelis Koukis | # interpreted as representing official policies, either expressed
|
32 | a5bc3755 | Vangelis Koukis | # or implied, of GRNET S.A.
|
33 | a5bc3755 | Vangelis Koukis | #
|
34 | edda4d30 | Markos Gogoulos | from django import http |
35 | edda4d30 | Markos Gogoulos | from django.conf import settings |
36 | e646ebe5 | Dimitris Moraitis | from django.utils.translation import activate, to_locale |
37 | e646ebe5 | Dimitris Moraitis | from django.utils.translation import check_for_language, get_language |
38 | e646ebe5 | Dimitris Moraitis | |
39 | edda4d30 | Markos Gogoulos | def set_language(request): |
40 | edda4d30 | Markos Gogoulos | """
|
41 | edda4d30 | Markos Gogoulos | Django's set_language function adapted to serve GET instead of POST
|
42 | edda4d30 | Markos Gogoulos | """
|
43 | edda4d30 | Markos Gogoulos | next = request.REQUEST.get('next', None) |
44 | edda4d30 | Markos Gogoulos | if not next: |
45 | edda4d30 | Markos Gogoulos | next = request.META.get('HTTP_REFERER', None) |
46 | edda4d30 | Markos Gogoulos | if not next: |
47 | edda4d30 | Markos Gogoulos | next = '/'
|
48 | edda4d30 | Markos Gogoulos | response = http.HttpResponseRedirect(next)
|
49 | edda4d30 | Markos Gogoulos | if request.method == 'GET': |
50 | edda4d30 | Markos Gogoulos | lang_code = request.GET.get('l', None) |
51 | edda4d30 | Markos Gogoulos | if lang_code and check_for_language(lang_code): |
52 | edda4d30 | Markos Gogoulos | if hasattr(request, 'session'): |
53 | edda4d30 | Markos Gogoulos | request.session['django_language'] = lang_code
|
54 | edda4d30 | Markos Gogoulos | else:
|
55 | edda4d30 | Markos Gogoulos | response.set_cookie(settings.LANGUAGE_COOKIE_NAME, lang_code) |
56 | edda4d30 | Markos Gogoulos | return response |