2026.06.04 frontend építés közben
This commit is contained in:
23
backend/app/core/translation_helper.py
Normal file
23
backend/app/core/translation_helper.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/core/translation_helper.py
|
||||
"""
|
||||
Helper functions for easy translation usage throughout the application.
|
||||
Provides convenient access to the TranslationService with automatic locale detection.
|
||||
"""
|
||||
from typing import Optional, Dict, Any
|
||||
from app.services.translation_service import TranslationService
|
||||
|
||||
def t(key: str, variables: Optional[Dict[str, Any]] = None, lang: Optional[str] = None) -> str:
|
||||
"""
|
||||
Shortcut function for TranslationService.get_text().
|
||||
Automatically uses the current request locale from context.
|
||||
|
||||
Usage:
|
||||
t("AUTH.REGISTRATION_SUCCESS")
|
||||
t("AUTH.WELCOME", {"name": "John"})
|
||||
t("ERROR.INVALID_TOKEN", lang="en")
|
||||
"""
|
||||
return TranslationService.get_text(key, lang=lang, variables=variables)
|
||||
|
||||
# Alias for backward compatibility
|
||||
get_text = t
|
||||
translate = t
|
||||
Reference in New Issue
Block a user