Localization
This commit is contained in:
parent
7c4df07961
commit
3b324f2b62
10
filters.py
10
filters.py
|
@ -1,8 +1,8 @@
|
|||
from flask import render_template
|
||||
from objects import glob
|
||||
|
||||
"""
|
||||
@glob.app.template_filter('load_module')
|
||||
def load_module(module_name):
|
||||
return render_template("modules/%s.html" % module_name)
|
||||
"""
|
||||
@glob.app.context_processor
|
||||
def locale():
|
||||
def _locale(lang, key):
|
||||
return glob.langs[lang][key] if key in glob.langs[lang] else key
|
||||
return dict(locale = _locale)
|
7
locale/en/side_nav.json
Normal file
7
locale/en/side_nav.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"lnk_dashboard": "Dashboard",
|
||||
"lnk_bills": "Bills",
|
||||
"lnk_receipts": "Receipts",
|
||||
"lnk_warranties": "Warranties",
|
||||
"ttl_economical": "Economical"
|
||||
}
|
7
locale/no/side_nav.json
Normal file
7
locale/no/side_nav.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"lnk_dashboard": "Dashbord",
|
||||
"lnk_bills": "Regninger",
|
||||
"lnk_receipts": "Kvitteringer",
|
||||
"lnk_warranties": "Garantier",
|
||||
"ttl_economical": "Økonomisk"
|
||||
}
|
|
@ -10,6 +10,8 @@ import bcrypt
|
|||
app = None # main.py -> Flask App
|
||||
sql_conn = None
|
||||
|
||||
langs = {}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Global variables that initializes on first load of module
|
||||
|
||||
|
@ -20,6 +22,19 @@ if not os.path.isfile("config.json"):
|
|||
with open("config.json", "r") as f:
|
||||
config = json.load(f)
|
||||
|
||||
path = "locale"
|
||||
for l in os.listdir(path):
|
||||
langs[l] = {}
|
||||
_path = "%s/%s" % (path, l)
|
||||
for f in os.listdir(_path):
|
||||
_f = "%s/%s" % (_path, f)
|
||||
with open(_f, "r", encoding = "UTF-8") as j:
|
||||
pnd = json.load(j)
|
||||
for k in pnd.keys():
|
||||
if k in langs[l]:
|
||||
raise Exception("Duplicate localization entries found in file %s" % _f)
|
||||
langs[l] = {**langs[l], **pnd}
|
||||
|
||||
def make_sql_connection():
|
||||
return mysql.connector.connect(**config["mysql"])
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
{% set LANG = "no" %} <!-- TODO: Dynamic lang swap -->
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
{% include 'layout/includes/boot-head.html' %}
|
||||
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/custom.css') }}">
|
||||
{% if title %}
|
||||
<title>Husstanden - {{ title }}</title>
|
||||
<title>Husstanden - {{ locale(LANG, title) }}</title>
|
||||
{% else %}
|
||||
<title>Husstanden</title>
|
||||
{% endif %}
|
||||
|
|
|
@ -105,29 +105,29 @@
|
|||
<div class="flex-column">
|
||||
<div> <!-- Collection -->
|
||||
<a class="item" href="{{ url_for('dashboard') }}">
|
||||
<i class="far fa-calendar-alt"></i><span>Dashboard</span>
|
||||
<i class="far fa-calendar-alt"></i><span>{{ locale(LANG, "lnk_dashboard") }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<h4>Economical</h4>
|
||||
<h4>{{ locale(LANG, "ttl_economical") }}</h4>
|
||||
</div>
|
||||
<div>
|
||||
<a class="item" href="{{ url_for('bills') }}">
|
||||
<i class="fas fa-money-check-alt"></i><span>Bills</span>
|
||||
<i class="fas fa-money-check-alt"></i><span>{{ locale(LANG, "lnk_bills") }}</span>
|
||||
</a>
|
||||
</div>
|
||||
<div>
|
||||
<a class="item" onclick="toggleCategory(this)">
|
||||
<i class="far fa-list-alt"></i><span>Receipts</span>
|
||||
<i class="far fa-list-alt"></i><span>{{ locale(LANG, "lnk_receipts") }}</span>
|
||||
<i class="fas fa-chevron-right"></i>
|
||||
</a>
|
||||
<div class="downtab hidden">
|
||||
<div class="flex-column">
|
||||
<div class="page">
|
||||
<a href="{{ url_for('receipts') }}">Receipts</a>
|
||||
<a href="{{ url_for('receipts') }}">{{ locale(LANG, "lnk_receipts") }}</a>
|
||||
</div>
|
||||
<div class="page">
|
||||
<a href="{{ url_for('warranties') }}">Warranties</a>
|
||||
<a href="{{ url_for('warranties') }}">{{ locale(LANG, "lnk_warranties") }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
</style>
|
||||
|
||||
<nav class="navbar topnav" style="margin-bottom: 10px;">
|
||||
<h3>{{ title }}</h3>
|
||||
<h3>{{ locale(LANG, title) }}</h3>
|
||||
<div>
|
||||
{% with messages = get_flashed_messages(with_categories = true) %}
|
||||
{% if messages %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% set title = "Bills" %}
|
||||
{% set title = "lnk_bills" %}
|
||||
|
||||
{% extends "layout/dash.html" %}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% set title = "Dashboard" %}
|
||||
{% set title = "lnk_dashboard" %}
|
||||
|
||||
{% extends "layout/dash.html" %}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user