You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 多语言支持说明
## 功能概述
MyQrCode 应用现在支持多国语言,包括英文和中文,英文为默认语言。
## 支持的语言
- 🇺🇸 **English (en)** - 默认语言
- 🇨🇳 **中文简体 (zh-Hans)**
## 文件结构
```
MyQrCode/
├── en.lproj/
│ └── Localizable.strings # 英文本地化字符串
├── zh-Hans.lproj/
│ └── Localizable.strings # 中文本地化字符串
├── LanguageManager.swift # 语言管理器
├── LanguageSettingsView.swift # 语言设置界面
├── ContentView.swift # 主界面(已本地化)
├── ScannerView.swift # 扫描界面(已本地化)
└── Info.plist # 语言配置
```
## 主要功能
### 1. 语言切换
- 在主界面右上角显示当前语言标识
- 点击语言标识进入语言设置界面
- 支持实时语言切换,无需重启应用
### 2. 本地化内容
- **应用标题**: MyQrCode
- **主界面**: 条码扫描器 / Barcode Scanner
- **扫描界面**: 扫描指令、按钮文本、提示信息
- **扫描线样式**: 5种样式的本地化名称
- **错误信息**: 扫描失败提示
- **语言设置**: 设置界面的所有文本
### 3. 语言管理
- 自动保存用户语言选择
- 应用启动时恢复上次选择的语言
- 支持系统语言检测
## 使用方法
### 切换语言
1. 在主界面点击右上角的语言标识
2. 在语言设置界面选择目标语言
3. 语言立即生效,无需重启
### 添加新语言
1. 创建新的 `.lproj` 文件夹(如 `ja.lproj`
2.`Localizable.strings` 中添加翻译
3.`Language` 枚举中添加新语言
4.`Info.plist` 中添加语言代码
## 技术实现
### 语言管理器 (LanguageManager)
- 单例模式管理语言状态
- 使用 UserDefaults 持久化语言设置
- 提供本地化字符串获取方法
### 本地化扩展
```swift
extension String {
var localized: String {
return LanguageManager.shared.localizedString(for: self)
}
}
```
### 通知系统
- 语言变化时发送 `languageChanged` 通知
- 界面自动响应语言变化
## 本地化字符串示例
### 英文 (en.lproj/Localizable.strings)
```strings
"main_title" = "Barcode Scanner";
"scan_instruction" = "Place QR code or barcode in the frame";
```
### 中文 (zh-Hans.lproj/Localizable.strings)
```strings
"main_title" = "条码扫描器";
"scan_instruction" = "将二维码或条形码放入框内";
```
## 注意事项
1. **默认语言**: 英文为默认语言,确保所有字符串都有英文版本
2. **字符串键**: 使用有意义的键名,便于维护
3. **格式字符串**: 支持 `String(format:)` 的格式化字符串
4. **实时更新**: 语言切换后界面立即更新
5. **持久化**: 语言选择保存在 UserDefaults 中
## 扩展建议
- 添加更多语言支持(日语、韩语、法语等)
- 支持系统语言自动检测
- 添加语言特定的日期和数字格式
- 支持 RTL 语言(阿拉伯语、希伯来语)