From cba32410ac14b15b5de01adb58420890e6fafbc9 Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Sat, 27 Dec 2025 18:13:45 +0100 Subject: [PATCH] fix: add i18n context to platform routes in main.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- main.py | 62 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/main.py b/main.py index 35cceff1..4435a7d7 100644 --- a/main.py +++ b/main.py @@ -38,6 +38,7 @@ from app.exceptions.handler import setup_exception_handlers # Import page routers 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.language import LanguageMiddleware 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 ) + # Get language from request state and build i18n context + language = getattr(request.state, "language", "fr") + i18n_globals = get_jinja2_globals(language) + if homepage: # Use template selection from CMS 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}") - return templates.TemplateResponse( - template_path, - { - "request": request, - "page": homepage, - "header_pages": header_pages, - "footer_pages": footer_pages, - }, - ) + context = { + "request": request, + "page": homepage, + "header_pages": header_pages, + "footer_pages": footer_pages, + } + context.update(i18n_globals) + + return templates.TemplateResponse(template_path, context) + # Fallback to default static template logger.info("[PLATFORM] No CMS homepage found, using default template") - return templates.TemplateResponse( - "platform/homepage-default.html", - { - "request": request, - "header_pages": header_pages, - "footer_pages": footer_pages, - }, - ) + context = { + "request": request, + "header_pages": header_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) @@ -428,15 +434,19 @@ async def platform_content_page( logger.info(f"[PLATFORM] Rendering content page: {page.title} (/{slug})") - return templates.TemplateResponse( - "platform/content-page.html", - { - "request": request, - "page": page, - "header_pages": header_pages, - "footer_pages": footer_pages, - }, - ) + # Get language from request state and build i18n context + language = getattr(request.state, "language", "fr") + i18n_globals = get_jinja2_globals(language) + + context = { + "request": request, + "page": page, + "header_pages": header_pages, + "footer_pages": footer_pages, + } + context.update(i18n_globals) + + return templates.TemplateResponse("platform/content-page.html", context) logger.info("=" * 80)