2026.06.04 frontend építés közben
This commit is contained in:
31
backend/app/core/context.py
Normal file
31
backend/app/core/context.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/core/context.py
|
||||
"""
|
||||
Context management for request-scoped variables, particularly locale/language.
|
||||
Uses contextvars to store the current request's locale for i18n purposes.
|
||||
"""
|
||||
import contextvars
|
||||
from typing import Optional
|
||||
|
||||
# Context variable to store the current request's locale
|
||||
# Default value is "hu" (Hungarian) as per project requirements
|
||||
current_locale: contextvars.ContextVar[str] = contextvars.ContextVar(
|
||||
"current_locale", default="hu"
|
||||
)
|
||||
|
||||
def get_current_locale() -> str:
|
||||
"""
|
||||
Get the current locale from the context.
|
||||
Returns the default "hu" if not set.
|
||||
"""
|
||||
return current_locale.get()
|
||||
|
||||
def set_current_locale(locale: str) -> None:
|
||||
"""
|
||||
Set the current locale in the context.
|
||||
Should be called by middleware or other request processors.
|
||||
"""
|
||||
current_locale.set(locale)
|
||||
|
||||
# Alias for convenience
|
||||
get_locale = get_current_locale
|
||||
set_locale = set_current_locale
|
||||
Reference in New Issue
Block a user