Skip to content

Commit 079598a

Browse files
committed
feat(i18n): 가이드·기준 페이지 영어 번역 — 언어 토글 시 EN 콘텐츠 제공
- /guides 응답이 한국어 고정이라 토글해도 번역 안 되던 문제 수정 - 8개 가이드에 title_en/content_en 추가(마크다운·코드블록·통제번호 보존) - routes/guides.py: ?lang= / mori_lang 쿠키로 언어 판별해 EN 노출(admin 편집분은 유지) - 프런트 loadGuide ?lang= 명시, risk_methodology 탭 라벨 i18n 키 추가
1 parent d1ab5fd commit 079598a

4 files changed

Lines changed: 567 additions & 6 deletions

File tree

src/mori_soc/api/i18n.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ def _i18n_toggle_html(fixed: bool = True) -> str:
535535
"dash.dyn.guide.ldap_setup": "LDAP 통합 설정",
536536
"dash.dyn.guide.incident_response": "인시던트 대응 절차",
537537
"dash.dyn.guide.security_policy": "보안 정책 가이드",
538+
"dash.dyn.guide.risk_methodology": "위험성 평가 기준",
538539
"dash.dyn.nlq_ex.0": "오프라인 호스트 보여줘",
539540
"dash.dyn.nlq_ex.1": "최근 24시간 wazuh high alert 요약",
540541
"dash.dyn.nlq_ex.2": "host-1 타임라인 보여줘",
@@ -1264,6 +1265,7 @@ def _i18n_toggle_html(fixed: bool = True) -> str:
12641265
"dash.dyn.guide.ldap_setup": "LDAP integration setup",
12651266
"dash.dyn.guide.incident_response": "Incident response",
12661267
"dash.dyn.guide.security_policy": "Security policy guide",
1268+
"dash.dyn.guide.risk_methodology": "Risk assessment criteria",
12671269
"dash.dyn.nlq_ex.0": "Show offline hosts",
12681270
"dash.dyn.nlq_ex.1": "Summarize wazuh high alerts in last 24h",
12691271
"dash.dyn.nlq_ex.2": "Show host-1 timeline",

src/mori_soc/api/routes/guides.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,48 @@
99
from datetime import datetime, timezone
1010
from typing import Any
1111

12-
from fastapi import HTTPException
12+
from fastapi import HTTPException, Request
1313

1414
from mori_soc.api.payloads import _isoformat
1515
from mori_soc.api.routes.context import RouteContext
1616

1717

18+
def _resolve_lang(request: Request) -> str:
19+
"""요청 언어 결정: ?lang= 우선, 없으면 mori_lang 쿠키, 기본 ko."""
20+
lang = (request.query_params.get("lang") or request.cookies.get("mori_lang") or "ko").lower()
21+
return "en" if lang == "en" else "ko"
22+
23+
24+
def _localize(guide: dict[str, Any], lang: str) -> dict[str, Any]:
25+
"""lang=en 이면 title_en/content_en 을 title/content 로 노출(없으면 한글 폴백).
26+
27+
관리자가 저장한 커스텀 내용(title/content)이 있으면 그것을 우선한다:
28+
``updated_at`` 이 설정돼 있으면 사용자가 편집한 것이므로 언어 치환하지 않는다.
29+
"""
30+
if lang != "en" or guide.get("updated_at"):
31+
return guide
32+
out = dict(guide)
33+
if guide.get("title_en"):
34+
out["title"] = guide["title_en"]
35+
if guide.get("content_en"):
36+
out["content"] = guide["content_en"]
37+
return out
38+
39+
1840
def register_guides(ctx: RouteContext) -> None:
1941
app = ctx.app
2042
guides = ctx.guides
2143

2244
@app.get("/guides")
23-
def guides_list() -> Any:
24-
return {"guides": list(guides.values())}
45+
def guides_list(request: Request) -> Any:
46+
lang = _resolve_lang(request)
47+
return {"guides": [_localize(g, lang) for g in guides.values()]}
2548

2649
@app.get("/guides/{guide_id}")
27-
def guide_get(guide_id: str) -> Any:
50+
def guide_get(guide_id: str, request: Request) -> Any:
2851
if guide_id not in guides:
2952
raise HTTPException(status_code=404, detail="guide not found")
30-
return guides[guide_id]
53+
return _localize(guides[guide_id], _resolve_lang(request))
3154

3255
@app.put("/guides/{guide_id}")
3356
def guide_upsert(guide_id: str, payload: dict[str, Any]) -> Any:

0 commit comments

Comments
 (0)