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
|
@babel.localeselector
|
||||||
def get_locale():
|
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)
|
setattr(g, 'lang', lang)
|
||||||
return lang
|
return lang
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,10 @@
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<div class="topbar">
|
||||||
<h3><a class="logo" href="{{ url_for(".home") }}">#! money?</a></h3>
|
<h3><a class="logo" href="{{ url_for(".home") }}">#! money?</a></h3>
|
||||||
{% if g.project %}
|
{% if g.project %}
|
||||||
|
@ -64,6 +67,11 @@
|
||||||
<li><a href="{{ url_for(".exit") }}">{{ _("Logout") }}</a></li>
|
<li><a href="{{ url_for(".exit") }}">{{ _("Logout") }}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
{{ translations() }}
|
||||||
|
</ul>
|
||||||
|
{% else %}
|
||||||
|
<ul class="nav secondary-nav">
|
||||||
|
{{ translations() }}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -323,6 +323,13 @@ def edit_bill(bill_id):
|
||||||
form.fill(bill)
|
form.fill(bill)
|
||||||
return render_template("add_bill.html", form=form, edit=True)
|
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")
|
@main.route("/<project_id>/compute")
|
||||||
def compute_bills():
|
def compute_bills():
|
||||||
"""Compute the sum each one have to pay to each other and display it"""
|
"""Compute the sum each one have to pay to each other and display it"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue