fix(i18n): pass locale to background threads via thread-local storage

Background threads (graph building, simulation prep, report generation,
profile generation) now inherit the requesting user's locale preference.
Previously these fell back to 'zh' because Flask request context was
unavailable in spawned threads.
This commit is contained in:
ghostubborn
2026-04-01 16:55:51 +08:00
parent 592ee52f59
commit 7c07237544
9 changed files with 54 additions and 14 deletions

View File

@@ -20,7 +20,7 @@ from zep_cloud.client import Zep
from ..config import Config
from ..utils.logger import get_logger
from ..utils.locale import get_language_instruction, t
from ..utils.locale import get_language_instruction, get_locale, set_locale, t
from .zep_entity_reader import EntityNode, ZepEntityReader
logger = get_logger('mirofish.oasis_profile')
@@ -916,8 +916,12 @@ class OasisProfileGenerator:
except Exception as e:
logger.warning(f"实时保存 profiles 失败: {e}")
# Capture locale before spawning thread pool workers
current_locale = get_locale()
def generate_single_profile(idx: int, entity: EntityNode) -> tuple:
"""生成单个profile的工作函数"""
set_locale(current_locale)
entity_type = entity.get_entity_type() or "Entity"
try: