Files
lair.moe/app.py
T

80 lines
1.9 KiB
Python
Raw Normal View History

2025-07-03 01:37:41 +03:00
from os import system as console
2025-08-09 02:28:03 +03:00
from configparser import ConfigParser
2025-12-04 20:21:09 +03:00
from htmlmin import minify
2025-08-09 02:28:03 +03:00
from flask import (
Flask,
g,
request,
render_template,
)
translations_cache = {}
def load_translations(lang):
if lang not in translations_cache:
translations_cache[lang] = {}
try:
config = ConfigParser()
config.read(f'locale/{lang}.ini')
for section in config.sections():
translations_cache[lang][section] = dict(config.items(section))
except:
pass
return translations_cache[lang]
def get_locale():
return request.accept_languages.best_match(('en', 'ru', 'de', 'fr', 'ja'), 'en')
2025-07-03 01:37:41 +03:00
app = Flask(__name__)
2025-08-07 21:16:47 +03:00
2025-08-09 02:28:03 +03:00
@app.before_request
def before_request():
g.locale = get_locale()
g.translations = load_translations(g.locale)
@app.context_processor
def inject_translations():
def translate(text, **kwargs):
if ":" in text:
section, key = text.split(":", 1)
else:
section, key = "common", text
template = g.translations \
.get(section, {}) \
.get(key, f"${section}: {key}$")
try:
return template.format(**kwargs)
except:
return template
return {'_': translate}
2025-08-07 21:16:47 +03:00
if app.debug:
console("sass static/style/main.scss static/style/main.css")
2025-09-05 13:57:52 +03:00
console("sass static/style/risdeveau.scss static/style/risdeveau.css")
2025-07-03 01:37:41 +03:00
@app.route("/")
def index():
2025-12-04 20:21:09 +03:00
return minify(render_template('index.html'), remove_empty_space=True)
2025-07-03 01:37:41 +03:00
@app.route("/host")
def host():
2025-12-04 20:21:09 +03:00
return minify(render_template('host.html'), remove_empty_space=True)
2025-07-03 01:37:41 +03:00
@app.route("/us")
def us():
2025-12-04 20:21:09 +03:00
return minify(render_template('us.html'), remove_empty_space=True)
2025-09-05 13:57:52 +03:00
@app.route("/risdeveau")
def risdeveau():
2025-12-04 20:21:09 +03:00
return minify(render_template('personal/risdeveau.html'), remove_empty_space=True)