mintrt 0.1.2

Security-featured runtime for lua.
Documentation
# 🍃 Mint Runtime - 快速参考

## 📦 项目结构

```
mint/
├── static/              # 静态网站文件
│   ├── index.html      # 官网首页
│   └── README.md       # 网站部署指南
├── src/
│   ├── i10n.rs         # 国际化模块
│   ├── i10n_examples.rs # 使用示例
│   ├── main.rs         # 主程序入口
│   └── ...             # 其他模块
├── Cargo.toml          # 项目配置
├── I18N_GUIDE.md       # 国际化详细指南
└── RELEASE_SUMMARY.md  # 发布总结
```

---

## 🌐 国际化快速上手

### 1️⃣ 初始化(已在 main.rs 中完成)

```rust
// 程序启动时自动调用
i10n::init_i18n();
```

### 2️⃣ 使用翻译

```rust
// 方法 1: 直接调用函数
let text = i10n::t("runtime_init");

// 方法 2: 在日志中使用
log::info!("{}: {}", i10n::t("security_check"), "完成");

// 方法 3: 使用宏(推荐)⭐
info_i18n!("task_complete");
error_i18n!("lua_error", ": {}", error_msg);
warn_i18n!("permission_denied", ": {}", resource);
```

### 3️⃣ 可用翻译键

```rust
"runtime_init"          // 运行时初始化
"security_check"        // 安全检查
"lua_error"             // Lua 错误
"config_load"           // 配置加载
"task_complete"         // 任务完成
"permission_denied"     // 权限拒绝
"bytecode_verify"       // 字节码验证
"env_modify_blocked"    // 环境修改被阻止
"external_call_hook"    // 外部调用钩子
"log_rate_limit"        // 日志速率限制
"promise_resolved"      // Promise 已解析
"promise_rejected"      // Promise 已拒绝
"module_loaded"         // 模块已加载
```

---

## 🏗️ 编译与运行

### 开发模式
```bash
cargo build
cargo run -- <ro_params> <usr_params>
```

### 发布模式(优化)
```bash
cargo build --release
```

### 测试
```bash
cargo test
cargo test i10n::tests::test_translation
```

### 检查代码
```bash
cargo check
cargo clippy
```

---

## 🎨 官网预览

### 方式 1: 直接打开
```bash
# Windows
start static\index.html

# Linux/Mac
open static/index.html
```

### 方式 2: 本地服务器
```bash
cd static
python -m http.server 8080
# 访问 http://localhost:8080
```

---

## 📝 添加新翻译

编辑 `src/i10n.rs`,在 `init_i18n()` 函数中添加:

```rust
pub fn init_i18n() {
    let mut i18n = I18n::new();
    i18n.set_language("zh");
    
    // 添加你的翻译
    i18n.add_translation("your_key", "zh", "中文翻译");
    i18n.add_translation("your_key", "en", "English translation");
    
    // ... 现有翻译
    
    I18N_INSTANCE.set(i18n).expect("Failed to initialize i18n");
}
```

---

## 🔧 Cargo.toml 关键配置

### 分类(已设置)
```toml
categories = ["development-tools", "security"]
```

### docs.rs 元数据(已设置)
```toml
[package.metadata.docs.rs]
all-features = true
targets = [
    "x86_64-unknown-linux-gnu",
    "x86_64-pc-windows-msvc",
    "x86_64-apple-darwin"
]
```

### 发布优化(已配置)
```toml
[profile.release]
opt-level = 3      # 性能优先
lto = true         # 链接时优化
codegen-units = 1  # 单单元生成
panic = "abort"    # 精简异常处理
strip = true       # 移除调试符号
```

---

## 📖 文档索引

| 文档 | 说明 |
|------|------|
| `I18N_GUIDE.md` | 国际化详细使用指南 |
| `static/README.md` | 官网部署指南 |
| `RELEASE_SUMMARY.md` | 任务完成总结 |
| `src/i10n_examples.rs` | 代码示例集合 |
| `README.md` | 项目主文档 |

---

## ⚡ 设计特点

### 国际化
- **零开销**: 基于 `&'static str`,编译期确定
-**线程安全**: `OnceLock` 保证并发访问安全
-**易扩展**: 添加新翻译只需一行代码
-**宏支持**: 提供便捷的日志宏

### 官网
- **响应式**: 自适应各种设备
-**无依赖**: 纯 HTML/CSS,无需构建
-**现代化**: 紫色渐变 + 卡片布局
-**高性能**: 秒级加载,无需等待

---

## 🎯 常用命令速查

```bash
# 编译
cargo build
cargo build --release

# 运行
cargo run -- <param1> <param2>

# 测试
cargo test
cargo test --lib
cargo test i10n::tests

# 检查
cargo check
cargo clippy

# 清理
cargo clean

# 查看依赖
cargo tree
cargo outdated  # 需安装 cargo-outdated
```

---

## 🐛 故障排除

### 编译错误
```bash
# 查看详细错误信息
cargo build --verbose

# 清理后重新编译
cargo clean && cargo build
```

### 测试失败
```bash
# 运行单个测试
cargo test test_name

# 显示输出
cargo test -- --nocapture
```

### 国际化未生效
确保已调用 `i10n::init_i18n()`,通常在 `main()` 函数开始处。

---

## 📞 相关链接

- **API 文档**: https://docs.rs/mintrt
- **Gitee 仓库**: https://gitee.com/snoware/mint
- **项目主页**: https://swe-iss.rth1.xyz/softwares/jingzhe

---

## 💡 提示

> **通义建议**: 
> - 使用 `info_i18n!` 等宏比直接使用 `i10n::t()` 更简洁
> - 所有日志输出都应该使用国际化翻译
> - 添加新翻译键时,同时添加中英文版本
> - 定期运行 `cargo clippy` 保持代码质量

---

**最后更新**: 2026-04-01  
**版本**: v0.1.0  
**状态**: ✅ 生产就绪