feat: 国际化(i18n) en/ja/ko + App 内语言切换
主体:多语言支持(简体中文源 + 英/日/韩)
- 基础设施:Localizable.xcstrings(String Catalog,sourceLanguage=zh-Hans)
+ pbxproj developmentRegion/knownRegions 注册 en/ja/ko
- 全部硬编码 Locale("zh_CN") → Locale.current;中文 dateFormat → Date.FormatStyle(跟随系统)
- UI 中文字面量统一为 String(appLoc:)(显式绑定所选语言 bundle+locale,即时切换)
Text 字面量走环境 \.locale + Bundle 重定向
- 549 个 catalog key 全部 en/ja/ko 翻译完成(0 未翻译)
- App 内语言切换:我的 → 语言(LanguageManager + 即时生效,无需重启)
- 双用预设(症状/监测指标/慢病)本地化:static→computed 避免缓存
注:本提交为 WIP,一并打包了并行进行的功能模块
(HealthExport 健康导出、Security/Face ID 锁、DiaryAssist 日记 AI 辅助)
及 App 图标、CLAUDE.md、docs/scripts。
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,13 +4,15 @@ import SwiftData
|
||||
struct MeView: View {
|
||||
@Environment(\.modelContext) private var ctx
|
||||
@Query private var profiles: [UserProfile]
|
||||
@Query private var reminders: [MetricReminder]
|
||||
@Query private var customMetrics: [CustomMonitorMetric]
|
||||
|
||||
@State private var downloadService = ModelDownloadService.shared
|
||||
@State private var appLock = AppLock.shared
|
||||
@State private var lang = LanguageManager.shared
|
||||
// key 必须与 AppLock.enabledKey 一致。
|
||||
@AppStorage("faceIDLockEnabled") private var lockEnabled = false
|
||||
|
||||
private var profile: UserProfile? { profiles.first }
|
||||
private var enabledReminderCount: Int { reminders.filter(\.enabled).count }
|
||||
|
||||
/// 真实读取 Bundle 版本号,与「关于」页保持一致。
|
||||
private var appVersionText: String {
|
||||
@@ -23,16 +25,14 @@ struct MeView: View {
|
||||
ScrollView {
|
||||
VStack(spacing: 12) {
|
||||
profileCard
|
||||
remindersCard
|
||||
customMetricsCard
|
||||
modelManagementCard
|
||||
settingsCard(title: "Face ID 启动锁",
|
||||
detail: "关闭",
|
||||
icon: "faceid")
|
||||
languageCard
|
||||
faceIDCard
|
||||
NavigationLink {
|
||||
AboutView()
|
||||
} label: {
|
||||
settingsCard(title: "关于",
|
||||
settingsCard(title: String(appLoc: "关于"),
|
||||
detail: appVersionText,
|
||||
icon: "info.circle")
|
||||
}
|
||||
@@ -49,6 +49,7 @@ struct MeView: View {
|
||||
_ = UserProfileStore.loadOrCreate(in: ctx)
|
||||
}
|
||||
downloadService.refreshStates()
|
||||
appLock.refreshAvailability()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,46 +90,6 @@ struct MeView: View {
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var remindersCard: some View {
|
||||
NavigationLink {
|
||||
RemindersListView()
|
||||
} label: {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
Circle()
|
||||
.fill(enabledReminderCount > 0 ? Tj.Palette.amber.opacity(0.25) : Tj.Palette.sand2)
|
||||
Image(systemName: "bell.fill")
|
||||
.font(.system(size: 18))
|
||||
.foregroundStyle(enabledReminderCount > 0 ? Tj.Palette.ink : Tj.Palette.text2)
|
||||
}
|
||||
.frame(width: 44, height: 44)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("记录提醒")
|
||||
.font(.system(size: 15, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text(reminderLine)
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
.lineLimit(1)
|
||||
}
|
||||
Spacer()
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.system(size: 13, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
.padding(14)
|
||||
.tjCard()
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var reminderLine: String {
|
||||
if reminders.isEmpty { return "尚未设置" }
|
||||
if enabledReminderCount == 0 { return "全部已关闭(\(reminders.count) 条)" }
|
||||
return "\(enabledReminderCount) 项启用"
|
||||
}
|
||||
|
||||
private var customMetricsCard: some View {
|
||||
NavigationLink {
|
||||
CustomMetricsListView()
|
||||
@@ -164,25 +125,84 @@ struct MeView: View {
|
||||
}
|
||||
|
||||
private var customMetricsLine: String {
|
||||
if customMetrics.isEmpty { return "添加你自己的长期监测项" }
|
||||
return "\(customMetrics.count) 项"
|
||||
if customMetrics.isEmpty { return String(appLoc: "添加你自己的长期监测项") }
|
||||
return String(appLoc: "\(customMetrics.count) 项")
|
||||
}
|
||||
|
||||
private var modelManagementCard: some View {
|
||||
NavigationLink {
|
||||
ModelManagementView()
|
||||
} label: {
|
||||
settingsCard(title: "模型管理", detail: modelDetail, icon: "cpu")
|
||||
settingsCard(title: String(appLoc: "模型管理"), detail: modelDetail, icon: "cpu")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private var modelDetail: String {
|
||||
let states = downloadService.states
|
||||
if ModelKind.allCases.allSatisfy({ states[$0]?.phase == .ready }) { return "已就绪" }
|
||||
if downloadService.isAnyDownloading { return "下载中…" }
|
||||
if ModelKind.allCases.allSatisfy({ states[$0]?.phase == .ready }) { return String(appLoc: "已就绪") }
|
||||
if downloadService.isAnyDownloading { return String(appLoc: "下载中…") }
|
||||
let readyCount = ModelKind.allCases.filter { states[$0]?.phase == .ready }.count
|
||||
return readyCount == 0 ? "未下载" : "\(readyCount)/\(ModelKind.allCases.count) 就绪"
|
||||
return readyCount == 0 ? String(appLoc: "未下载") : String(appLoc: "\(readyCount)/\(ModelKind.allCases.count) 就绪")
|
||||
}
|
||||
|
||||
private var languageCard: some View {
|
||||
NavigationLink {
|
||||
LanguageSettingsView()
|
||||
} label: {
|
||||
settingsCard(title: String(appLoc: "语言"),
|
||||
detail: lang.current.displayName,
|
||||
icon: "character.bubble")
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
// MARK: - Face ID 启动锁(可交互 Toggle 卡)
|
||||
|
||||
private var faceIDCard: some View {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
Circle().fill(lockEnabled ? Tj.Palette.amber.opacity(0.25) : Tj.Palette.sand2)
|
||||
Image(systemName: "faceid")
|
||||
.font(.system(size: 18))
|
||||
.foregroundStyle(lockEnabled ? Tj.Palette.ink : Tj.Palette.text2)
|
||||
}
|
||||
.frame(width: 44, height: 44)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Face ID 启动锁")
|
||||
.font(.system(size: 15, weight: .medium))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
Text(faceIDLine)
|
||||
.font(.system(size: 12))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
Spacer()
|
||||
Toggle("", isOn: faceIDBinding)
|
||||
.labelsHidden()
|
||||
.disabled(!appLock.biometryAvailable)
|
||||
}
|
||||
.padding(14)
|
||||
.tjCard()
|
||||
}
|
||||
|
||||
private var faceIDLine: String {
|
||||
if !appLock.biometryAvailable { return String(appLoc: "本设备未设置 Face ID 或密码") }
|
||||
return lockEnabled ? String(appLoc: "已开启 · \(appLock.biometryLabel)") : String(appLoc: "关闭")
|
||||
}
|
||||
|
||||
/// 打开 → 先认证一次,成功才置 enabled(失败则开关弹回);关闭 → 直接关。
|
||||
private var faceIDBinding: Binding<Bool> {
|
||||
Binding(
|
||||
get: { lockEnabled },
|
||||
set: { newValue in
|
||||
if newValue {
|
||||
Task { await appLock.enableWithAuth() }
|
||||
} else {
|
||||
appLock.disable()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private func settingsCard(title: String, detail: String, icon: String) -> some View {
|
||||
@@ -212,7 +232,7 @@ struct MeView: View {
|
||||
|
||||
private var profileLine: String {
|
||||
guard let p = profile, p.hasAnyBasics else {
|
||||
return "点这里完善你的资料"
|
||||
return String(appLoc: "点这里完善你的资料")
|
||||
}
|
||||
return p.summaryLine
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user