Commit 8ed11d2d authored by Štěpán Henek's avatar Štěpán Henek 🌩

proper translations in jinja2 templates

parent 3c195afb
......@@ -57,7 +57,7 @@ def prepare_common_app(args, app_name, init_function, top_index, logger, load_pl
# internationalization
i18n_defaults(bottle.SimpleTemplate, bottle.request)
i18n_defaults(bottle.Jinja2Template, bottle.request)
bottle.Jinja2Template.settings["extensions"] = ['jinja2.ext.i18n']
bottle.Jinja2Template.settings["extensions"] = ['foris.utils.translators.i18n']
# setup default template defaults
prepare_template_defaults()
......
<span class="minor-text">{{ trans("foris version:") }} {{ foris_info.foris_version }} </span>
<span class="minor-text">{% trans %}foris version:{% endtrans %} {{ foris_info.foris_version }} </span>
{{ trans("Language") }}:
{% trans %}Language{% endtrans %}:
<span>{{ iso2to3.get(lang(), lang()) }}</span>
{% for code in translations %}
{% if code != lang() %}
......
......@@ -2,7 +2,7 @@
<html lang="{{ lang() }}">
<head>
<meta charset="utf-8">
<title>{{ title + " | " if title|default(False) else "" }}{{ trans("Turris router administration interface") }}</title>
<title>{{ title + " | " if title|default(False) else "" }}{% trans %}Turris router administration interface{% endtrans %}</title>
<!--[if gt IE 8]><!--><link href="{{ static("css/screen.css") }}" rel="stylesheet" media="screen"><!--<![endif]-->
<!--[if lt IE 9]>
<script src="{{ static("js/contrib/html5.js") }}"></script>
......
......@@ -6,6 +6,6 @@
<noscript>
<div class="message info">
{{ trans("This page requires JavaScript for proper function. Please enable it and refresh the page.") }}
{% trans %}This page requires JavaScript for proper function. Please enable it and refresh the page.{% endtrans %}
</div>
</noscript>
......@@ -11,27 +11,27 @@
{% include '_lang_flat.html.j2' %}
</div>
<h1><img src="{{ static("img/logo-turris.svg") }}" alt="{{ trans("Project:Turris") }}" width="295"></h1>
<h1><img src="{{ static("img/logo-turris.svg") }}" alt="{% trans %}Project:Turris{% endtrans %}" width="295"></h1>
{% include '_messages.html.j2' %}
{% if user_authenticated() %}
<a href="{{ url("logout") }}">{{ trans("Log out") }}</a>
<a href="{{ url("logout") }}">{% trans %}Log out{% endtrans %}</a>
{% else %}
<form action="{{ request.fullpath }}{{ '?next=%s' % next if next else '' }}" method="POST">
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
{% if request.GET.get("next") %}
<input type="hidden" name="next" value="{{ request.GET['next'] }}">
{% endif %}
<label for="field-password">{{ trans("Password") }}</label>
<input id="field-password" type="password" name="password" placeholder="{{ trans("Password") }}" autofocus>
<button class="button" type="submit">{{ trans("Log in") }}</button>
<label for="field-password">{% trans %}Password{% endtrans %}</label>
<input id="field-password" type="password" name="password" placeholder="{% trans %}Password{% endtrans %}" autofocus>
<button class="button" type="submit">{% trans %}Log in{% endtrans %}</button>
</form>
{% endif %}
<div class="footer">
{{ trans("Foris Configuration Interface") }}<br>
{% trans %}Foris Configuration Interface{% endtrans %}<br>
{% if luci_path is defined %}
<a href="{{ luci_path }}">{{ trans("Go to LuCI") }}</a>
<a href="{{ luci_path }}">{% trans %}Go to LuCI{% endtrans %}</a>
{% endif %}
</div>
......@@ -40,12 +40,12 @@
<input type="checkbox" hidden id="flash-1">
<label for="flash-1" class="flash warning">
<span>
<img src="{{ static("img/icon-opened-lock.png") }}" alt="{{ trans("Opened lock") }}" width="64" height="64">
<img src="{{ static("img/icon-opened-lock.png") }}" alt="{% trans %}Opened lock{% endtrans %}" width="64" height="64">
</span>
<strong>{{ trans("Your connection is not encrypted") }}!</strong>
<strong>{% trans %}Your connection is not encrypted{% endtrans %}</strong>
<br>
{{ trans("A secure connection is an important safety feature of the router and therefore the entire home network.") }}
<a href="{{ doc_url }}">{{ trans("How to set an encrypted connection and why is it important") }} &gt;</a>
<a href="{{ doc_url }}">{% trans %}How to set an encrypted connection and why is it important{% endtrans %} &gt;</a>
<br>
<small>Turris OS</small>
</label>
......
......@@ -19,6 +19,8 @@ import collections
import gettext
import os
from jinja2.ext import InternationalizationExtension
from foris import BASE_DIR
from foris.langs import translations
from foris.state import current_state
......@@ -59,3 +61,13 @@ def set_current_language(language):
return True
return False
# for jinja template
class ForisInternationalizationExtension(InternationalizationExtension):
def __init__(self, environment):
super(ForisInternationalizationExtension, self).__init__(environment)
self._install_callables(ugettext, ungettext)
i18n = ForisInternationalizationExtension
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment