mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-28 02:33:12 -05:00
feat: Customize Ingredient Plural Handling (#7057)
This commit is contained in:
0
mealie/middleware/__init__.py
Normal file
0
mealie/middleware/__init__.py
Normal file
22
mealie/middleware/locale_context.py
Normal file
22
mealie/middleware/locale_context.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from fastapi import Request
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from mealie.lang.providers import get_locale_config, get_locale_provider, set_locale_context
|
||||
|
||||
|
||||
class LocaleContextMiddleware(BaseHTTPMiddleware):
|
||||
"""
|
||||
Inject translator and locale config into context var.
|
||||
This allows any part of the app to call get_locale_context, as long as it's within an HTTP request context.
|
||||
"""
|
||||
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
accept_language = request.headers.get("accept-language")
|
||||
translator = get_locale_provider(accept_language)
|
||||
locale_config = get_locale_config(accept_language)
|
||||
|
||||
# Set context for this request
|
||||
set_locale_context(translator, locale_config)
|
||||
|
||||
response = await call_next(request)
|
||||
return response
|
||||
Reference in New Issue
Block a user