S allius/issue385 (#386)

* ignore translation and log files

* add quart-babel

* build and install translation files

* don't export the web-ui port 8127

- for security reason the user should use the
  HA ingress and not the direkt access to the web
  dashboard

* set 'lang' in html tag
This commit is contained in:
Stefan Allius
2025-04-19 16:51:06 +02:00
committed by GitHub
parent b82941bd38
commit c270edff15
12 changed files with 93 additions and 12 deletions

View File

@@ -4,7 +4,9 @@ import logging.handlers
import os
import argparse
from asyncio import StreamReader, StreamWriter
from quart import Quart, Response
from quart import Quart, Response, request
from quart_babel import Babel
from quart_babel.locale import get_locale
from logging import config # noqa F401
from proxy import Proxy
from inverter_ifc import InverterIfc
@@ -31,12 +33,28 @@ class ProxyState:
ProxyState._is_up = value
def my_get_locale():
# check how to get the locale form for the add-on - hass.selectedLanguage
# logging.info("get_locale(%s)", request.accept_languages)
return request.accept_languages.best_match(
['de', 'en']
)
app = Quart(__name__,
template_folder='web/templates',
static_folder='web/static')
babel = Babel(app,
locale_selector=my_get_locale,
default_translation_directories='../translations')
app.register_blueprint(web_routes)
@app.context_processor
def utility_processor():
return dict(lang=get_locale())
@app.route('/-/ready')
async def ready():
if ProxyState.is_up():