From 3a8451c119757e625d81c930a10612a52c8dc640 Mon Sep 17 00:00:00 2001 From: ghostubborn Date: Wed, 1 Apr 2026 17:21:55 +0800 Subject: [PATCH] feat(i18n): replace remaining hardcoded Chinese in frontend addLog calls --- frontend/src/components/Step3Simulation.vue | 50 ++++++++++---------- frontend/src/components/Step5Interaction.vue | 32 ++++++------- frontend/src/views/InteractionView.vue | 24 +++++----- frontend/src/views/MainView.vue | 6 +-- frontend/src/views/ReportView.vue | 24 +++++----- 5 files changed, 70 insertions(+), 66 deletions(-) diff --git a/frontend/src/components/Step3Simulation.vue b/frontend/src/components/Step3Simulation.vue index 32e136e2..5b0f968c 100644 --- a/frontend/src/components/Step3Simulation.vue +++ b/frontend/src/components/Step3Simulation.vue @@ -22,7 +22,7 @@ {{ runStatus.twitter_current_round || 0 }}/{{ runStatus.total_rounds || maxRounds || '-' }} - Elapsed Time + TIME {{ twitterElapsedTime }} @@ -63,7 +63,7 @@ {{ runStatus.reddit_current_round || 0 }}/{{ runStatus.total_rounds || maxRounds || '-' }} - Elapsed Time + TIME {{ redditElapsedTime }} @@ -382,16 +382,16 @@ const resetAllState = () => { // 启动模拟 const doStartSimulation = async () => { if (!props.simulationId) { - addLog('错误:缺少 simulationId') + addLog(t('log.errorMissingSimId')) return } - + // 先重置所有状态,确保不会受到上一次模拟的影响 resetAllState() isStarting.value = true startError.value = null - addLog('正在启动双平台并行模拟...') + addLog(t('log.startingDualSim')) emit('update-status', 'processing') try { @@ -404,18 +404,18 @@ const doStartSimulation = async () => { if (props.maxRounds) { params.max_rounds = props.maxRounds - addLog(`设置最大模拟轮数: ${props.maxRounds}`) + addLog(t('log.setMaxRounds', { rounds: props.maxRounds })) } - addLog('已开启动态图谱更新模式') + addLog(t('log.graphMemoryUpdateEnabled')) const res = await startSimulation(params) if (res.success && res.data) { if (res.data.force_restarted) { - addLog('✓ 已清理旧的模拟日志,重新开始模拟') + addLog(t('log.oldSimCleared')) } - addLog('✓ 模拟引擎启动成功') + addLog(t('log.engineStarted')) addLog(` ├─ PID: ${res.data.process_pid || '-'}`) phase.value = 1 @@ -425,12 +425,12 @@ const doStartSimulation = async () => { startDetailPolling() } else { startError.value = res.error || '启动失败' - addLog(`✗ 启动失败: ${res.error || '未知错误'}`) + addLog(t('log.startFailed', { error: res.error || t('common.unknownError') })) emit('update-status', 'error') } } catch (err) { startError.value = err.message - addLog(`✗ 启动异常: ${err.message}`) + addLog(t('log.startException', { error: err.message })) emit('update-status', 'error') } finally { isStarting.value = false @@ -442,21 +442,21 @@ const handleStopSimulation = async () => { if (!props.simulationId) return isStopping.value = true - addLog('正在停止模拟...') + addLog(t('log.stoppingSim')) try { const res = await stopSimulation({ simulation_id: props.simulationId }) if (res.success) { - addLog('✓ 模拟已停止') + addLog(t('log.simStoppedSuccess')) phase.value = 2 stopPolling() emit('update-status', 'completed') } else { - addLog(`停止失败: ${res.error || '未知错误'}`) + addLog(t('log.stopFailed', { error: res.error || t('common.unknownError') })) } } catch (err) { - addLog(`停止异常: ${err.message}`) + addLog(t('log.stopException', { error: err.message })) } finally { isStopping.value = false } @@ -520,9 +520,9 @@ const fetchRunStatus = async () => { if (isCompleted || platformsCompleted) { if (platformsCompleted && !isCompleted) { - addLog('✓ 检测到所有平台模拟已结束') + addLog(t('log.allPlatformsCompleted')) } - addLog('✓ 模拟已完成') + addLog(t('log.simCompleted')) phase.value = 2 stopPolling() emit('update-status', 'completed') @@ -643,17 +643,17 @@ const formatActionTime = (timestamp) => { const handleNextStep = async () => { if (!props.simulationId) { - addLog('错误:缺少 simulationId') + addLog(t('log.errorMissingSimId')) return } - + if (isGeneratingReport.value) { - addLog('报告生成请求已发送,请稍候...') + addLog(t('log.reportRequestSent')) return } isGeneratingReport.value = true - addLog('正在启动报告生成...') + addLog(t('log.startingReportGen')) try { const res = await generateReport({ @@ -663,16 +663,16 @@ const handleNextStep = async () => { if (res.success && res.data) { const reportId = res.data.report_id - addLog(`✓ 报告生成任务已启动: ${reportId}`) + addLog(t('log.reportGenTaskStarted', { reportId })) // 跳转到报告页面 router.push({ name: 'Report', params: { reportId } }) } else { - addLog(`✗ 启动报告生成失败: ${res.error || '未知错误'}`) + addLog(t('log.reportGenFailed', { error: res.error || t('common.unknownError') })) isGeneratingReport.value = false } } catch (err) { - addLog(`✗ 启动报告生成异常: ${err.message}`) + addLog(t('log.reportGenException', { error: err.message })) isGeneratingReport.value = false } } @@ -688,7 +688,7 @@ watch(() => props.systemLogs?.length, () => { }) onMounted(() => { - addLog('Step3 模拟运行初始化') + addLog(t('log.step3Init')) if (props.simulationId) { doStartSimulation() } diff --git a/frontend/src/components/Step5Interaction.vue b/frontend/src/components/Step5Interaction.vue index cd721c65..075ba41c 100644 --- a/frontend/src/components/Step5Interaction.vue +++ b/frontend/src/components/Step5Interaction.vue @@ -538,7 +538,7 @@ const selectAgent = (agent, idx) => { // 恢复该 Agent 的对话记录 chatHistory.value = chatHistoryCache.value[`agent_${idx}`] || [] - addLog(`选择对话对象: ${agent.username}`) + addLog(t('log.selectChatTarget', { name: agent.username })) } const formatTime = (timestamp) => { @@ -665,7 +665,7 @@ const sendMessage = async () => { await sendToAgent(message) } } catch (err) { - addLog(`发送失败: ${err.message}`) + addLog(t('log.sendFailed', { error: err.message })) chatHistory.value.push({ role: 'assistant', content: t('step5.errorOccurred', { error: err.message }), @@ -680,7 +680,7 @@ const sendMessage = async () => { } const sendToReportAgent = async (message) => { - addLog(`向 Report Agent 发送: ${message.substring(0, 50)}...`) + addLog(t('log.sendToReportAgent', { message: message.substring(0, 50) })) // Build chat history for API const historyForApi = chatHistory.value @@ -703,7 +703,7 @@ const sendToReportAgent = async (message) => { content: res.data.response || res.data.answer || t('step5.noResponse'), timestamp: new Date().toISOString() }) - addLog('Report Agent 已回复') + addLog(t('log.reportAgentReplied')) } else { throw new Error(res.error || t('step5.requestFailed')) } @@ -714,7 +714,7 @@ const sendToAgent = async (message) => { throw new Error(t('step5.selectAgentFirst')) } - addLog(`向 ${selectedAgent.value.username} 发送: ${message.substring(0, 50)}...`) + addLog(t('log.sendToAgent', { name: selectedAgent.value.username, message: message.substring(0, 50) })) // Build prompt with chat history let prompt = message @@ -764,7 +764,7 @@ const sendToAgent = async (message) => { content: responseContent, timestamp: new Date().toISOString() }) - addLog(`${selectedAgent.value.username} 已回复`) + addLog(t('log.agentReplied', { name: selectedAgent.value.username })) } else { throw new Error(t('step5.noResponse')) } @@ -806,7 +806,7 @@ const submitSurvey = async () => { if (selectedAgents.value.size === 0 || !surveyQuestion.value.trim()) return isSurveying.value = true - addLog(`发送问卷给 ${selectedAgents.value.size} 个对象...`) + addLog(t('log.sendSurvey', { count: selectedAgents.value.size })) try { const interviews = Array.from(selectedAgents.value).map(idx => ({ @@ -860,12 +860,12 @@ const submitSurvey = async () => { } surveyResults.value = surveyResultsList - addLog(`收到 ${surveyResults.value.length} 条回复`) + addLog(t('log.receivedReplies', { count: surveyResults.value.length })) } else { throw new Error(res.error || t('step5.requestFailed')) } } catch (err) { - addLog(`问卷发送失败: ${err.message}`) + addLog(t('log.surveySendFailed', { error: err.message })) } finally { isSurveying.value = false } @@ -876,7 +876,7 @@ const loadReportData = async () => { if (!props.reportId) return try { - addLog(`加载报告数据: ${props.reportId}`) + addLog(t('log.loadReportData', { id: props.reportId })) // Get report info const reportRes = await getReport(props.reportId) @@ -885,7 +885,7 @@ const loadReportData = async () => { await loadAgentLogs() } } catch (err) { - addLog(`加载报告失败: ${err.message}`) + addLog(t('log.loadReportFailed', { error: err.message })) } } @@ -907,10 +907,10 @@ const loadAgentLogs = async () => { } }) - addLog('报告数据加载完成') + addLog(t('log.reportDataLoaded')) } } catch (err) { - addLog(`加载报告日志失败: ${err.message}`) + addLog(t('log.loadReportLogFailed', { error: err.message })) } } @@ -921,10 +921,10 @@ const loadProfiles = async () => { const res = await getSimulationProfilesRealtime(props.simulationId, 'reddit') if (res.success && res.data) { profiles.value = res.data.profiles || [] - addLog(`加载了 ${profiles.value.length} 个模拟个体`) + addLog(t('log.loadedProfiles', { count: profiles.value.length })) } } catch (err) { - addLog(`加载模拟个体失败: ${err.message}`) + addLog(t('log.loadProfilesFailed', { error: err.message })) } } @@ -938,7 +938,7 @@ const handleClickOutside = (e) => { // Lifecycle onMounted(() => { - addLog('Step5 深度互动初始化') + addLog(t('log.step5Init')) loadReportData() loadProfiles() document.addEventListener('click', handleClickOutside) diff --git a/frontend/src/views/InteractionView.vue b/frontend/src/views/InteractionView.vue index a2de0f4e..7e555b26 100644 --- a/frontend/src/views/InteractionView.vue +++ b/frontend/src/views/InteractionView.vue @@ -66,6 +66,7 @@ diff --git a/frontend/src/views/MainView.vue b/frontend/src/views/MainView.vue index 41a0a374..513c70d8 100644 --- a/frontend/src/views/MainView.vue +++ b/frontend/src/views/MainView.vue @@ -164,11 +164,11 @@ const toggleMaximize = (target) => { const handleNextStep = (params = {}) => { if (currentStep.value < 5) { currentStep.value++ - addLog(`进入 Step ${currentStep.value}: ${stepNames.value[currentStep.value - 1]}`) + addLog(t('log.enterStep', { step: currentStep.value, name: stepNames.value[currentStep.value - 1] })) // 如果是从 Step 2 进入 Step 3,记录模拟轮数配置 if (currentStep.value === 3 && params.maxRounds) { - addLog(`自定义模拟轮数: ${params.maxRounds} 轮`) + addLog(t('log.customSimRounds', { rounds: params.maxRounds })) } } } @@ -176,7 +176,7 @@ const handleNextStep = (params = {}) => { const handleGoBack = () => { if (currentStep.value > 1) { currentStep.value-- - addLog(`返回 Step ${currentStep.value}: ${stepNames.value[currentStep.value - 1]}`) + addLog(t('log.returnToStep', { step: currentStep.value, name: stepNames.value[currentStep.value - 1] })) } } diff --git a/frontend/src/views/ReportView.vue b/frontend/src/views/ReportView.vue index e8dbf5a6..ac054e47 100644 --- a/frontend/src/views/ReportView.vue +++ b/frontend/src/views/ReportView.vue @@ -66,6 +66,7 @@