fix(i18n): register _() Jinja2 global and current_locale in error handlers
All checks were successful
ci/woodpecker/pr/pipeline Pipeline was successful
All checks were successful
ci/woodpecker/pr/pipeline Pipeline was successful
Error handlers had a separate Jinja2Templates instance without the _
global function, causing UndefinedError when rendering base.html
(which now calls {{ _(key, current_locale) }}).
- Register _() from translator module as Jinja2 global on error_handlers templates
- Add current_locale to get_template_context() from request.state.locale
This commit is contained in:
@@ -10,9 +10,11 @@ from fastapi import HTTPException, Request
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from app.infrastructure.i18n.translator import DEFAULT_LOCALE, _
|
||||
from app.presentation.web.flash import FlashManager, get_flash_messages
|
||||
|
||||
templates = Jinja2Templates(directory="app/presentation/templates")
|
||||
templates.env.globals["_"] = _
|
||||
|
||||
|
||||
async def setup_flash_manager(request: Request) -> None:
|
||||
@@ -55,6 +57,7 @@ def get_template_context(request: Request) -> dict[str, Any]:
|
||||
"user_role": user_role.value if user_role else None,
|
||||
"can_create": can_create_post(user),
|
||||
"flash_messages": get_flash_messages(request),
|
||||
"current_locale": getattr(request.state, "locale", DEFAULT_LOCALE),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user