aboutsummaryrefslogtreecommitdiff
path: root/budget
diff options
context:
space:
mode:
authorAlexis Metaireau <alexis@notmyidea.org>2011-10-17 00:03:41 +0200
committerAlexis Metaireau <alexis@notmyidea.org>2011-10-17 00:03:41 +0200
commitdb7e1496b0af8f6270b8304055f2aabb2428fbe0 (patch)
tree27e3abb27642a3b5bb341316de4a7fa77599f88d /budget
parentf7a969240a984c6eb63662331ad7767283088efc (diff)
downloadihatemoney-mirror-db7e1496b0af8f6270b8304055f2aabb2428fbe0.zip
ihatemoney-mirror-db7e1496b0af8f6270b8304055f2aabb2428fbe0.tar.gz
ihatemoney-mirror-db7e1496b0af8f6270b8304055f2aabb2428fbe0.tar.bz2
Add the ability to change the language explicitely. I'm not sure the UI is better with this. Any thoughts are welcome. Fix #35
Diffstat (limited to 'budget')
-rw-r--r--budget/run.py4
-rw-r--r--budget/templates/layout.html10
-rw-r--r--budget/web.py7
3 files changed, 19 insertions, 2 deletions
diff --git a/budget/run.py b/budget/run.py
index ebcf45e..3d57329 100644
--- a/budget/run.py
+++ b/budget/run.py
@@ -24,7 +24,9 @@ babel = Babel(app)
@babel.localeselector
def get_locale():
- lang = request.accept_languages.best_match(['fr', 'en'])
+ # get the lang from the session if defined, fallback on the browser "accept
+ # languages" header.
+ lang = session.get('lang', request.accept_languages.best_match(['fr', 'en']))
setattr(g, 'lang', lang)
return lang
diff --git a/budget/templates/layout.html b/budget/templates/layout.html
index e6614d8..c546e1e 100644
--- a/budget/templates/layout.html
+++ b/budget/templates/layout.html
@@ -41,7 +41,10 @@
</script>
</head>
<body>
-
+{% macro translations() %}
+<li {% if g.lang == "fr" %}class="active"{% endif %}><a href="{{ url_for(".change_lang", lang="fr") }}">fr</a></li>
+<li {% if g.lang == "en" %}class="active"{% endif %}><a href="{{ url_for(".change_lang", lang="en") }}">en</a></li>
+{% endmacro %}
<div class="topbar">
<h3><a class="logo" href="{{ url_for(".home") }}">#! money?</a></h3>
{% if g.project %}
@@ -64,6 +67,11 @@
<li><a href="{{ url_for(".exit") }}">{{ _("Logout") }}</a></li>
</ul>
</li>
+ {{ translations() }}
+ </ul>
+ {% else %}
+ <ul class="nav secondary-nav">
+ {{ translations() }}
</ul>
{% endif %}
</div>
diff --git a/budget/web.py b/budget/web.py
index 1daecd7..82bb5f8 100644
--- a/budget/web.py
+++ b/budget/web.py
@@ -323,6 +323,13 @@ def edit_bill(bill_id):
form.fill(bill)
return render_template("add_bill.html", form=form, edit=True)
+@main.route("/lang/<lang>")
+def change_lang(lang):
+ session['lang'] = lang
+ session.update()
+
+ return redirect(request.headers.get('Referer') or url_for('.home'))
+
@main.route("/<project_id>/compute")
def compute_bills():
"""Compute the sum each one have to pay to each other and display it"""