mirror of
https://github.com/YunoHost-Apps/ihatemoney_ynh.git
synced 2024-09-03 19:26:15 +02:00
Add the ability to change the language explicitely. I'm not sure the UI is better with this. Any thoughts are welcome. Fix #35
This commit is contained in:
parent
f7a969240a
commit
db7e1496b0
3 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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"""
|
||||
|
|
Loading…
Add table
Reference in a new issue