fix: add i18n context to platform routes in main.py
The platform homepage and content page routes in main.py were missing i18n globals (_(), t(), current_language, etc.) which caused template rendering errors when using translation functions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
40
main.py
40
main.py
@@ -38,6 +38,7 @@ from app.exceptions.handler import setup_exception_handlers
|
|||||||
|
|
||||||
# Import page routers
|
# Import page routers
|
||||||
from app.routes import admin_pages, platform_pages, shop_pages, vendor_pages
|
from app.routes import admin_pages, platform_pages, shop_pages, vendor_pages
|
||||||
|
from app.utils.i18n import get_jinja2_globals
|
||||||
from middleware.context import ContextMiddleware
|
from middleware.context import ContextMiddleware
|
||||||
from middleware.language import LanguageMiddleware
|
from middleware.language import LanguageMiddleware
|
||||||
from middleware.logging import LoggingMiddleware
|
from middleware.logging import LoggingMiddleware
|
||||||
@@ -360,6 +361,10 @@ async def platform_homepage(request: Request, db: Session = Depends(get_db)):
|
|||||||
db, vendor_id=None, footer_only=True, include_unpublished=False
|
db, vendor_id=None, footer_only=True, include_unpublished=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Get language from request state and build i18n context
|
||||||
|
language = getattr(request.state, "language", "fr")
|
||||||
|
i18n_globals = get_jinja2_globals(language)
|
||||||
|
|
||||||
if homepage:
|
if homepage:
|
||||||
# Use template selection from CMS
|
# Use template selection from CMS
|
||||||
template_name = homepage.template or "default"
|
template_name = homepage.template or "default"
|
||||||
@@ -367,26 +372,27 @@ async def platform_homepage(request: Request, db: Session = Depends(get_db)):
|
|||||||
|
|
||||||
logger.info(f"[PLATFORM] Rendering CMS homepage with template: {template_path}")
|
logger.info(f"[PLATFORM] Rendering CMS homepage with template: {template_path}")
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
context = {
|
||||||
template_path,
|
|
||||||
{
|
|
||||||
"request": request,
|
"request": request,
|
||||||
"page": homepage,
|
"page": homepage,
|
||||||
"header_pages": header_pages,
|
"header_pages": header_pages,
|
||||||
"footer_pages": footer_pages,
|
"footer_pages": footer_pages,
|
||||||
},
|
}
|
||||||
)
|
context.update(i18n_globals)
|
||||||
|
|
||||||
|
return templates.TemplateResponse(template_path, context)
|
||||||
|
|
||||||
# Fallback to default static template
|
# Fallback to default static template
|
||||||
logger.info("[PLATFORM] No CMS homepage found, using default template")
|
logger.info("[PLATFORM] No CMS homepage found, using default template")
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
context = {
|
||||||
"platform/homepage-default.html",
|
|
||||||
{
|
|
||||||
"request": request,
|
"request": request,
|
||||||
"header_pages": header_pages,
|
"header_pages": header_pages,
|
||||||
"footer_pages": footer_pages,
|
"footer_pages": footer_pages,
|
||||||
},
|
}
|
||||||
)
|
context.update(i18n_globals)
|
||||||
|
|
||||||
|
return templates.TemplateResponse("platform/homepage-default.html", context)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/{slug}", response_class=HTMLResponse, include_in_schema=False)
|
@app.get("/{slug}", response_class=HTMLResponse, include_in_schema=False)
|
||||||
@@ -428,15 +434,19 @@ async def platform_content_page(
|
|||||||
|
|
||||||
logger.info(f"[PLATFORM] Rendering content page: {page.title} (/{slug})")
|
logger.info(f"[PLATFORM] Rendering content page: {page.title} (/{slug})")
|
||||||
|
|
||||||
return templates.TemplateResponse(
|
# Get language from request state and build i18n context
|
||||||
"platform/content-page.html",
|
language = getattr(request.state, "language", "fr")
|
||||||
{
|
i18n_globals = get_jinja2_globals(language)
|
||||||
|
|
||||||
|
context = {
|
||||||
"request": request,
|
"request": request,
|
||||||
"page": page,
|
"page": page,
|
||||||
"header_pages": header_pages,
|
"header_pages": header_pages,
|
||||||
"footer_pages": footer_pages,
|
"footer_pages": footer_pages,
|
||||||
},
|
}
|
||||||
)
|
context.update(i18n_globals)
|
||||||
|
|
||||||
|
return templates.TemplateResponse("platform/content-page.html", context)
|
||||||
|
|
||||||
|
|
||||||
logger.info("=" * 80)
|
logger.info("=" * 80)
|
||||||
|
|||||||
Reference in New Issue
Block a user