Skip to content

Commit 2da1da0

Browse files
committed
feat: introduce internationalization for job status notifications and refactor job card styling for localization compatibility
1 parent eeb8e32 commit 2da1da0

5 files changed

Lines changed: 47 additions & 13 deletions

File tree

agents/matmaster_agent/callback.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313

1414
from agents.matmaster_agent.base_agents.callback import _get_ak
1515
from agents.matmaster_agent.constant import FRONTEND_STATE_KEY
16+
from agents.matmaster_agent.locales import i18n
1617
from agents.matmaster_agent.model import UserContent
1718
from agents.matmaster_agent.prompt import get_user_content_lang
18-
from agents.matmaster_agent.style import JobCompleteCard
19+
from agents.matmaster_agent.style import get_job_complete_card
1920
from agents.matmaster_agent.utils.job_utils import get_job_status, has_job_running, get_running_jobs_detail
2021

2122
logger = logging.getLogger(__name__)
@@ -75,10 +76,9 @@ async def matmaster_check_job_status(callback_context: CallbackContext, llm_resp
7576
running_job_ids = get_running_jobs_detail(jobs_dict) # 从 state 里面拿
7677
access_key = _get_ak(callback_context) # 从 state 或环境变量里面拿
7778
if callback_context.state['target_language'] in ['Chinese', 'zh-CN', '简体中文', 'Chinese (Simplified)']:
78-
job_complete_intro = '检测到任务 <{job_id}> 已完成,我将立刻转移至对应的 Agent 去获取任务结果。'
79+
i18n.language = "zh"
7980
else:
80-
job_complete_intro = ('Job <{job_id}> has been detected as completed. '
81-
'I will immediately transfer to the corresponding agent to retrieve the job results.')
81+
i18n.language = "en"
8282

8383
reset = False
8484
for origin_job_id, job_id, job_query_url, agent_name in running_job_ids:
@@ -101,7 +101,7 @@ async def matmaster_check_job_status(callback_context: CallbackContext, llm_resp
101101
reset = True
102102
function_call_id = f"call_{str(uuid.uuid4()).replace('-', '')[:24]}"
103103
callback_context.state['origin_job_id'] = origin_job_id
104-
llm_response.content.parts.append(Part(text=JobCompleteCard.format(job_id=job_id)))
104+
llm_response.content.parts.append(Part(text=get_job_complete_card(i18n=i18n, job_id=job_id)))
105105
llm_response.content.parts.append(Part(function_call=FunctionCall(id=function_call_id,
106106
name='transfer_to_agent',
107107
args={'agent_name': agent_name})))

agents/matmaster_agent/locales.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from toolsy.i8n import I18N
2+
3+
translations = {
4+
"en": {
5+
"JobStatus": "Job Status",
6+
"Job": "Job",
7+
"JobCompleted": "Job Completed",
8+
"ResultRetrieving": "Result Retrieving"
9+
},
10+
"zh": {
11+
"JobStatus": "任务状态",
12+
"Job": "任务",
13+
"JobCompleted": "任务已完成",
14+
"ResultRetrieving": "结果获取中"
15+
}
16+
}
17+
18+
i18n = I18N(translations=translations)

agents/matmaster_agent/style.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
JobCompleteCard = """
1+
from toolsy.i8n import I18N
2+
3+
4+
def get_job_complete_card(i18n: I18N, job_id):
5+
return f"""
26
<div style="
37
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
48
border-radius: 12px;
@@ -15,23 +19,24 @@
1519
backdrop-filter: blur(10px);
1620
font-size: 12px;
1721
font-weight: bold;
18-
">🚀 任务状态</div>
22+
">🚀 {i18n.t("JobStatus")}</div>
1923
<div style="
2024
background: rgba(255, 255, 255, 0.1);
2125
padding: 4px 10px;
2226
border-radius: 6px;
2327
font-family: monospace;
24-
">ID: {job_id}</div>
28+
font-size: 12px;
29+
">{i18n.t("Job")}ID:{job_id}</div>
2530
</div>
2631
<div style="
2732
font-size: 16px;
2833
font-weight: 500;
2934
margin-top: 8px;
30-
">已完成 · 正在转移至 Agent</div>
35+
">{i18n.t("JobCompleted")}</div>
3136
<div style="
32-
font-size: 12px;
37+
font-size: 14px;
3338
opacity: 0.9;
34-
margin-top: 4px;
35-
">结果获取中...</div>
39+
margin-top: 6px;
40+
">{i18n.t("ResultRetrieving")}...</div>
3641
</div>
37-
"""
42+
"""

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"google-adk[a2a]==1.14.1",
1717
"pre-commit>=4.3.0",
1818
"bohrium-sdk>=0.14.0",
19+
"toolsy>=0.1.2",
1920
]
2021

2122
[tool.setuptools]

uv.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)