diff options
-rw-r--r-- | static/lang_de.png | bin | 0 -> 545 bytes | |||
-rw-r--r-- | static/lang_en.png | bin | 0 -> 599 bytes | |||
-rw-r--r-- | static/layout.css | 4 | ||||
-rw-r--r-- | templates/login.html | 2 | ||||
-rw-r--r-- | tmpl.py | 16 |
5 files changed, 19 insertions, 3 deletions
diff --git a/static/lang_de.png b/static/lang_de.png Binary files differnew file mode 100644 index 0000000..ac4a977 --- /dev/null +++ b/static/lang_de.png diff --git a/static/lang_en.png b/static/lang_en.png Binary files differnew file mode 100644 index 0000000..ff701e1 --- /dev/null +++ b/static/lang_en.png diff --git a/static/layout.css b/static/layout.css index d54d79e..a1c59cf 100644 --- a/static/layout.css +++ b/static/layout.css @@ -136,5 +136,7 @@ body#error pre { color:#ffb100; } - +a.lang img { + margin:2px; +} diff --git a/templates/login.html b/templates/login.html index 09b130c..3ca7299 100644 --- a/templates/login.html +++ b/templates/login.html @@ -17,5 +17,7 @@ <b class="error" py:if="'password' in errors">${errors.password}</b> <input type='submit' value='login'/> </form> + <a href="login?lang=de" class="lang"><img src="${url('static/lang_de.png')}" alt="Deutsch" width="16" height="11"/></a> + <a href="login?lang=en" class="lang"><img src="${url('static/lang_en.png')}" alt="English" width="16" height="11"/></a> </sub:bodyform> </html> @@ -22,7 +22,9 @@ def select_language(): lang = cherrypy.thread_data.lang return languages[lang if languages.has_key(lang) else 'en'] accept = cherrypy.request.headers['Accept-Language'] - if isinstance(accept, str): + try: accept = str(accept) + except: accept = None + if accept is not None: for group in accept.split(';'): for lang in group.split(','): if lang.find('=') >= 0: @@ -65,10 +67,20 @@ def expose(filename, method='html', encoding='utf-8', **options): cherrypy.thread_data.template = loader.load(filename) cherrypy.thread_data.func = func cherrypy.thread_data.lang = None + if cherrypy.request.cookie.has_key('lang'): + cherrypy.thread_data.lang = cherrypy.request.cookie['lang'].value + if cherrypy.request.params.has_key('lang'): + cherrypy.thread_data.lang = cherrypy.request.params['lang'] + if cherrypy.thread_data.lang != None: + cherrypy.response.cookie['lang'] = cherrypy.thread_data.lang + cherrypy.response.cookie['lang']['path'] = '/' + cherrypy.response.cookie['lang']['max-age'] = 2419200 + cherrypy.response.cookie['lang']['version'] = 1 if kwargs.has_key('lang'): - cherrypy.thread_data.lang = kwargs['lang'] del kwargs['lang'] + cherrypy.thread_data.translations = select_language() + cherrypy.response.headers['Vary'] = 'Accept-Language' opt = options.copy() if method == 'html': |