Fix date/time localization

This commit is contained in:
Fabian Müller 2023-04-20 03:00:41 +02:00
parent f2b25ce868
commit 527d9642bc
4 changed files with 11 additions and 15 deletions

View File

@ -8,6 +8,8 @@ services:
- 5000:5000
environment:
- FABCAL_CACHE_EXPIRE=120
- LANG=de
- LC_ALL=de_DE.UTF-8
volumes:
- ./config.yml:/app/config.yml:ro
# use the line below when running this behind reverse proxy (only if it sets the proxy headers, though)

View File

@ -1,5 +1,6 @@
import re
from babel.dates import format_datetime
from jinja2 import pass_eval_context
from markupsafe import Markup, escape
from starlette.templating import Jinja2Templates
@ -7,6 +8,9 @@ from starlette.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
# custom filters
templates.env.filters["format_datetime"] = lambda value, format: format_datetime(value, format) #, locale="de_DE")
@pass_eval_context
def nl2br(eval_ctx, value):

View File

@ -18,19 +18,9 @@ async def generate_response(request: Request, template_name: str, **additional_c
grouped_events = list(group_by_date(events).items())
# couple of helpers
def localized_abbreviated_month(dt: datetime):
return babel.dates.format_datetime(dt, format="%b", locale="de_DE")
# couple of helpers
def localized_abbreviated_weekday(dt: datetime):
return babel.dates.format_datetime(dt, format="%b", locale="de_DE")
context = {
"request": request,
"grouped_events": grouped_events,
"localized_abbreviated_month": localized_abbreviated_month,
"localized_abbreviated_weekday": localized_abbreviated_weekday,
}
context.update(additional_context)

View File

@ -6,22 +6,22 @@
<div class="calendar-date">
<div class="calendar-date-date">
<div class="calendar-date-month">
{{ start_date.strftime("%b") }}
{{ start_date | format_datetime("MMM") }}
</div>
<div class="calendar-date-day">
{{ start_date.strftime("%d") }}
{{ start_date | format_datetime("d") }}
</div>
<div class="calendar-date-weekday">
{{ start_date.strftime("%a") }}
{{ start_date | format_datetime("EEE") }}
</div>
</div>
<div class="calendar-events">
{% for event in events %}
<div class="calendar-event" title="{{ event.summary }}{% if event.description %} &mdash; {{ event.description }}{% endif %}">
<div class="calendar-event-time">
<div class="calendar-event-starttime">{{ event.start.strftime("%H:%M") }}</div>
<div class="calendar-event-starttime">{{ event.start | format_datetime("HH:mm") }}</div>
<div class="calendar-event-timesep"></div>
<div class="calendar-event-endtime">{{ event.end.strftime("%H:%M") }}</div>
<div class="calendar-event-endtime">{{ event.end | format_datetime("HH:mm") }}</div>
</div>
<div class="calendar-event-description">
{% if event.description or event.location %}