Files
xiaomihome/miot/BATCH4_TASKS.md
T
4566704 3a44cb9e6a feat: 初始化小米 IoT (MIoT) 智能家居 Go 库
- 实现 MIoT 客户端核心功能(MQTT 连接、设备管理、属性读写)
- 支持云端 API 调用与局域网设备发现(mDNS)
- 集成国际化(i18n)多语言支持
- 添加 MIoT 设备规约解析器(spec_parser)
- 包含单元测试与使用示例
2026-06-28 22:05:49 +08:00

58 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 第四批移植任务提示词 (P3 附加功能) ✅ 已完成
> 源文件在 `D:\miot\py-miot\`,已完成:2026-06-28
## 任务 4.1 — miot_i18n.py → miot_i18n.go
```
源文件:D:\miot\py-miot\miot_i18n.py
目标文件:D:\miot\go-miot\miot_i18n.go(新建)
实现国际化翻译(MIoTI18n):
1. MIoTI18n 结构体
- 字段:lang string, data map[string]interface{}
- Init() — 加载 i18n/{lang}.json
- Deinit() — 清空数据
2. Translate(key string, replace map[string]string) string
- 用点号分隔 key,逐级查找嵌套 JSON(如 "device.light.name" → data["device"]["light"]["name"])
- 支持占位符替换:{key} → replace["key"]
### 注意事项
- JSON 文件在 go-miot/i18n/ 目录(需从 py-miot/i18n/ 复制)
- 键不存在返回空字符串(非 error)
- 无外部依赖
```
---
## 任务 4.2 — web_pages.py → web_pages.go
```
源文件:D:\miot\py-miot\web_pages.py
目标文件:D:\miot\go-miot\web_pages.go(新建)
实现 OAuth 重定向页面:
1. OAuthRedirectPage(title, content, button string, success bool) string
- 读取 resource/oauth_redirect_page.html 模板
- 替换 TITLE_PLACEHOLDER / CONTENT_PLACEHOLDER / BUTTON_PLACEHOLDER / STATUS_PLACEHOLDER
### 注意事项
- HTML 模板需从 py-miot/resource/ 复制到 go-miot/resource/
- 用 Go embed 嵌入模板文件,编译时打包
- 无外部依赖
```
---
## 第四批执行顺序
```
miot_i18n → miot_web_pages
(独立) (独立,无依赖)
```
无需等其他批次,两个任务完全独立可直接执行。