Coverage for .claude/hooks/moai/lib/announcement_translator.py: 0.00%
60 statements
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-19 08:00 +0900
« prev ^ index » next coverage.py v7.11.3, created at 2025-11-19 08:00 +0900
1"""
2Automatic announcement translation system for companyAnnouncements in .claude/settings.json
4This module copies and translates the 23 reference English announcements into the user's
5selected language during moai-adk init and update operations.
7Supported Languages:
8- Hardcoded: English (en), Korean (ko), Japanese (ja), Chinese (zh)
9- Other languages: Default to English fallback
10"""
12import json
13from pathlib import Path
14from typing import List, Optional
16# Reference English announcements (23 items - synced with settings.json template)
17REFERENCE_ANNOUNCEMENTS_EN = [
18 "SPEC-First: Use /moai:1-plan to define requirements first and everything connects together",
19 "TDD Cycle: RED (write tests) → GREEN (minimal code) → REFACTOR (improve) ensures quality",
20 "4-Phase Workflow: /moai:1-plan plan → /moai:2-run implement → /moai:3-sync validate → git deploy",
21 "TRUST 5 Principles: Test(≥85%) + Readable + Unified + Secured(OWASP) + Trackable = Quality",
22 "moai Agents: 19 expert team members automatically handle planning, implementation, testing, validation",
23 "Conversation Style: /output-style r2d2 (hands-on partner) or /output-style yoda (deep learning) available",
24 "Task Tracking: TodoWrite keeps progress visible and prevents any tasks from being missed",
25 "55+ Skill Library: Verified patterns and best practices enable hallucination-free implementation",
26 "Auto Validation: After coding, TRUST 5, test coverage, and security checks run automatically",
27 "GitFlow Strategy: feature/SPEC-XXX → develop → main structure for safe deployment pipeline",
28 "Context7 Updates: All library versions stay current with real-time API information",
29 "Parallel Processing: Independent tasks (tests, docs, deployment) run simultaneously to save time",
30 "Health Check: moai-adk doctor diagnoses configuration, version, and dependency issues in seconds",
31 "Doc Sync: /moai:3-sync auto synchronizes tests, code, and documentation automatically",
32 "Language Separation: Communicate in your language, write code in project language, package in English",
33 "Multi-language Support: Korean, English, Japanese, Spanish, and 25+ languages for conversation",
34 "Safe Updates: moai-adk update brings new features automatically while preserving existing settings",
35 "Auto Cleanup: Session end automatically cleans .moai/temp/ cache and logs to save space",
36 "Error Recovery: Failed commits and merge conflicts are auto-analyzed with solutions provided",
37 "Security First: Environment variables, API keys, and credentials auto-added to .gitignore for protection",
38 "Context Optimization: Efficient use of 200K token window enables handling of large projects",
39 "Quick Feedback: Questions? Ask immediately - moai interprets intent and clarifies automatically",
40 "Clean Exit: End sessions with /clear to reset context and prepare for the next task"
41]
43# Hardcoded Korean translations (23 items)
44ANNOUNCEMENTS_KO = [
45 "SPEC 우선: /moai:1-plan으로 요구사항을 먼저 정의하면 모든 것이 연결됩니다",
46 "TDD Cycle: RED (테스트 작성) → GREEN (최소 코드) → REFACTOR (개선)로 품질을 보장합니다",
47 "4단계 워크플로우: /moai:1-plan 계획 → /moai:2-run 구현 → /moai:3-sync 검증 → git 배포",
48 "TRUST 5 원칙: Test(≥85%) + Readable + Unified + Secured(OWASP) + Trackable = 품질",
49 "moai Agents: 19명의 전문가 팀이 계획, 구현, 테스트, 검증을 자동으로 처리합니다",
50 "대화 스타일: /output-style r2d2 (실습 파트너) 또는 /output-style yoda (심화 학습) 사용 가능",
51 "작업 추적: TodoWrite로 진행 상황을 계속 표시하여 누락되는 작업이 없습니다",
52 "55+ Skill 라이브러리: 검증된 패턴과 모범 사례로 환각 없는 구현을 가능하게 합니다",
53 "자동 검증: 코딩 후 TRUST 5, 테스트 커버리지, 보안 검사가 자동으로 실행됩니다",
54 "GitFlow 전략: feature/SPEC-XXX → develop → main 구조로 안전한 배포 파이프라인",
55 "Context7 업데이트: 모든 라이브러리 버전이 실시간 API 정보로 최신 상태를 유지합니다",
56 "병렬 처리: 독립적인 작업(테스트, 문서, 배포)을 동시에 실행하여 시간을 절약합니다",
57 "상태 확인: moai-adk doctor로 구성, 버전, 종속성 문제를 몇 초 만에 진단합니다",
58 "문서 동기화: /moai:3-sync로 테스트, 코드, 문서를 자동으로 동기화합니다",
59 "언어 분리: 당신의 언어로 소통하고, 프로젝트 언어로 코드를 작성하며, 영어로 패키징합니다",
60 "다국어 지원: 한국어, 영어, 일본어, 스페인어 등 25개 이상 언어로 대화할 수 있습니다",
61 "안전한 업데이트: moai-adk update로 기존 설정을 유지하면서 새 기능을 자동으로 추가합니다",
62 "자동 정리: 세션 종료 시 .moai/temp/ 캐시와 로그를 자동으로 정리하여 공간을 절약합니다",
63 "오류 복구: 실패한 커밋과 병합 충돌을 자동으로 분석하고 해결책을 제공합니다",
64 "보안 우선: 환경 변수, API 키, 자격 증명을 자동으로 .gitignore에 추가하여 보호합니다",
65 "컨텍스트 최적화: 200K 토큰 윈도우를 효율적으로 사용하여 대규모 프로젝트를 처리합니다",
66 "빠른 피드백: 질문이 있으신가요? 즉시 물어보세요 - moai가 의도를 파악하고 명확히 합니다",
67 "깔끔한 종료: /clear로 세션을 종료하여 컨텍스트를 재설정하고 다음 작업을 준비합니다"
68]
70# Hardcoded Japanese translations (23 items)
71ANNOUNCEMENTS_JA = [
72 "SPEC優先: /moai:1-planで要件を先に定義し、すべてが連携します",
73 "TDD Cycle: RED (テスト作成) → GREEN (最小コード) → REFACTOR (改善)で品質を保証",
74 "4段階ワークフロー: /moai:1-plan計画 → /moai:2-run実装 → /moai:3-sync検証 → gitデプロイ",
75 "TRUST 5原則: Test(≥85%) + Readable + Unified + Secured(OWASP) + Trackable = 品質",
76 "moaiエージェント: 19名の専門家チームが計画、実装、テスト、検証を自動処理",
77 "対話スタイル: /output-style r2d2 (実習パートナー) または /output-style yoda (深い学習) 利用可能",
78 "タスク追跡: TodoWriteで進捗を表示し、タスク漏れを防止",
79 "55+ Skillライブラリ: 検証済みパターンとベストプラクティスで幻想のない実装を実現",
80 "自動検証: コード作成後、TRUST 5、テストカバレッジ、セキュリティチェックが自動実行",
81 "GitFlow戦略: feature/SPEC-XXX → develop → main構造で安全なデプロイパイプライン",
82 "Context7更新: すべてのライブラリバージョンがリアルタイムAPI情報で最新を維持",
83 "並列処理: 独立したタスク(テスト、ドキュメント、デプロイ)を同時実行し時間節約",
84 "ヘルスチェック: moai-adk doctorで設定、バージョン、依存関係の問題を数秒で診断",
85 "ドキュメント同期: /moai:3-syncでテスト、コード、ドキュメントを自動同期",
86 "言語の分離: あなたの言語でコミュニケーション、プロジェクト言語でコード、英語でパッケージ",
87 "多言語対応: 韓国語、英語、日本語、スペイン語など25言語以上で会話可能",
88 "安全な更新: moai-adk updateで既存設定を保持しながら新機能を自動追加",
89 "自動クリーンアップ: セッション終了時に.moai/temp/キャッシュとログを自動削除してスペース節約",
90 "エラー復旧: 失敗したコミットとマージ衝突を自動分析し解決策を提供",
91 "セキュリティ優先: 環境変数、APIキー、認証情報を自動的に.gitignoreに追加して保護",
92 "コンテキスト最適化: 200Kトークンウィンドウを効率的に活用して大規模プロジェクト処理",
93 "迅速なフィードバック: 質問がありますか?即座に聞いてください - moaiが意図を理解し明確にします",
94 "きれいな終了: /clearでセッションを終了し、コンテキストをリセットして次のタスク準備"
95]
97# Hardcoded Chinese translations (23 items)
98ANNOUNCEMENTS_ZH = [
99 "SPEC优先: 使用 /moai:1-plan 先定义需求,一切都会相互连接",
100 "TDD循环: RED (编写测试) → GREEN (最小代码) → REFACTOR (改进) 确保质量",
101 "4阶段工作流: /moai:1-plan计划 → /moai:2-run实现 → /moai:3-sync验证 → git部署",
102 "TRUST 5原则: Test(≥85%) + Readable + Unified + Secured(OWASP) + Trackable = 质量",
103 "moai代理: 19名专家团队自动处理计划、实现、测试和验证",
104 "对话风格: /output-style r2d2 (实践伙伴) 或 /output-style yoda (深度学习) 可用",
105 "任务跟踪: TodoWrite持续显示进度,确保不遗漏任何任务",
106 "55+ Skill库: 经过验证的模式和最佳实践实现无幻觉实现",
107 "自动验证: 编码后,TRUST 5、测试覆盖率、安全检查自动运行",
108 "GitFlow策略: feature/SPEC-XXX → develop → main结构保证安全部署",
109 "Context7更新: 所有库版本通过实时API信息保持最新",
110 "并行处理: 独立任务 (测试、文档、部署) 同时运行节省时间",
111 "健康检查: moai-adk doctor在几秒内诊断配置、版本和依赖问题",
112 "文档同步: /moai:3-sync auto自动同步测试、代码和文档",
113 "语言分离: 用您的语言沟通,用项目语言编写代码,用英语打包",
114 "多语言支持: 韩语、英语、日语、西班牙语等25种以上语言交流",
115 "安全更新: moai-adk update在保留现有设置的同时自动添加新功能",
116 "自动清理: 会话结束时自动清理 .moai/temp/ 缓存和日志节省空间",
117 "错误恢复: 自动分析失败的提交和合并冲突并提供解决方案",
118 "安全第一: 环境变量、API密钥、凭据自动添加到 .gitignore保护",
119 "上下文优化: 有效利用200K令牌窗口处理大型项目",
120 "快速反馈: 有问题吗?立即提问 - moai理解意图并澄清",
121 "干净退出: 使用 /clear结束会话,重置上下文并为下一个任务做准备"
122]
124# Hardcoded translations dictionary (only en, ko, ja, zh supported)
125HARDCODED_TRANSLATIONS = {
126 "en": REFERENCE_ANNOUNCEMENTS_EN,
127 "ko": ANNOUNCEMENTS_KO,
128 "ja": ANNOUNCEMENTS_JA,
129 "zh": ANNOUNCEMENTS_ZH
130}
133def get_language_from_config(project_root: Optional[Path] = None) -> str:
134 """
135 Retrieve conversation_language from .moai/config/config.json
137 Args:
138 project_root: Project root directory (defaults to current working directory)
140 Returns:
141 Language code (e.g., "ko", "en", "ja", "es")
142 """
143 if project_root is None:
144 project_root = Path.cwd()
146 # Try both possible paths: .moai/config/config.json and .moai/config.json
147 config_paths = [
148 project_root / ".moai" / "config" / "config.json", # New structure
149 project_root / ".moai" / "config.json", # Legacy structure
150 ]
152 for config_path in config_paths:
153 if config_path.exists():
154 try:
155 with open(config_path, "r", encoding="utf-8") as f:
156 config = json.load(f)
157 return config.get("language", {}).get("conversation_language", "en")
158 except Exception:
159 pass
161 return "en" # Default to English if no config found
164def copy_settings_to_local(
165 language_code: str,
166 announcements: List[str],
167 project_root: Optional[Path] = None
168) -> None:
169 """
170 Copy settings.json to settings.local.json with translated announcements
172 Only supports hardcoded languages: en, ko, ja, zh
173 Other languages default to English
175 Args:
176 language_code: Language code (en, ko, ja, zh, etc.)
177 announcements: List of translated announcement strings
178 project_root: Project root directory (defaults to current working directory)
179 """
180 if project_root is None:
181 project_root = Path.cwd()
183 settings_path = project_root / ".claude" / "settings.json"
184 settings_local_path = project_root / ".claude" / "settings.local.json"
185 claude_dir = settings_local_path.parent
187 # Create .claude directory if needed
188 claude_dir.mkdir(parents=True, exist_ok=True)
190 try:
191 # Load settings.json
192 if settings_path.exists():
193 with open(settings_path, "r", encoding="utf-8") as f:
194 settings = json.load(f)
195 else:
196 # Create default settings if template doesn't exist
197 settings = {
198 "_meta": {
199 "description": "Claude Code settings (generated from template)",
200 },
201 "hooks": {},
202 "permissions": {},
203 }
205 # Replace companyAnnouncements with translated version
206 settings["companyAnnouncements"] = announcements
208 # Write to settings.local.json
209 with open(settings_local_path, "w", encoding="utf-8") as f:
210 json.dump(settings, f, indent=2, ensure_ascii=False)
212 print(f"[announcement_translator] Copied announcements to settings.local.json ({language_code})")
214 except Exception as e:
215 print(f"[announcement_translator] ERROR copying settings: {e}")
218def translate_announcements(language_code: str, project_root: Optional[Path] = None) -> List[str]:
219 """
220 Get announcements in specified language from hardcoded translations
222 Args:
223 language_code: Target language code (e.g., "ko", "en", "ja", "zh")
224 project_root: Project root directory (optional, not used in this simplified version)
226 Returns:
227 List of 23 announcement strings in the specified language.
228 Returns English (REFERENCE_ANNOUNCEMENTS_EN) if language not found.
229 """
230 # Check if language has hardcoded translation
231 if language_code in HARDCODED_TRANSLATIONS:
232 return HARDCODED_TRANSLATIONS[language_code]
234 # For unknown languages, default to English
235 print(f"[announcement_translator] Language '{language_code}' not supported, using English")
236 return REFERENCE_ANNOUNCEMENTS_EN
239def auto_translate_and_update(project_root: Optional[Path] = None) -> None:
240 """
241 Auto-copy announcements to settings.local.json
243 Workflow:
244 1. Read language from .moai/config/config.json
245 2. Get 23 announcements (hardcoded: en, ko, ja, zh)
246 3. Copy to settings.local.json with language-specific announcements
248 Supports: en (English), ko (Korean), ja (Japanese), zh (Chinese)
249 Other languages default to English (23 announcements)
251 This is the main function called by init and update commands.
253 Args:
254 project_root: Project root directory (defaults to current working directory)
255 """
256 if project_root is None:
257 project_root = Path.cwd()
259 # Step 1: Get language from config
260 language = get_language_from_config(project_root)
261 print(f"[announcement_translator] Detected language: {language}")
263 # Step 2: Get announcements (hardcoded only, no dynamic translation)
264 announcements = translate_announcements(language, project_root)
266 # Step 3: Copy settings.json to settings.local.json
267 copy_settings_to_local(language, announcements, project_root)
270if __name__ == "__main__":
271 """
272 CLI entry point for direct execution:
274 Usage:
275 python announcement_translator.py [language_code] [project_root]
277 If language_code is not provided, reads from .moai/config/config.json
278 If project_root is not provided, uses current directory
279 """
280 import sys
282 if len(sys.argv) > 1:
283 # Manual language and project root override
284 lang = sys.argv[1]
285 project_root = Path(sys.argv[2]) if len(sys.argv) > 2 else Path.cwd()
286 announcements = translate_announcements(lang, project_root)
287 copy_settings_to_local(lang, announcements, project_root)
288 else:
289 # Auto-detect from config and update
290 auto_translate_and_update()