23 lines
856 B
Python
23 lines
856 B
Python
# /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 |