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:
link2026
2026-05-30 10:28:24 +08:00
parent 910ca99f21
commit d2c77d5c51
84 changed files with 15643 additions and 699 deletions

View File

@@ -0,0 +1,158 @@
import Foundation
import LocalAuthentication
import SwiftUI
import Observation
/// Face ID ()
///
/// `docs/superpowers/specs/2026-05-30-faceid-app-lock-design.md`
/// 线(CLAUDE.md §10.2): `LocalAuthentication`,
///
/// `ModelDownloadService.shared` :`@MainActor @Observable`
/// UI(`AppLockContainer` / `MeView` / `LockScreenView`) observable ,
/// `handleAppear` / `handleScenePhase` / `authenticate`
@MainActor
@Observable
final class AppLock {
static let shared = AppLock()
///
static let gracePeriod: TimeInterval = 60
/// key, `MeView` `@AppStorage`
static let enabledKey = "faceIDLockEnabled"
// MARK: - Observable
/// ()
private(set) var isLocked = false
/// / ()
private(set) var showsPrivacyCover = false
/// ( false)
private(set) var biometryAvailable = false
/// / :"Face ID" / "Touch ID" / ""
private(set) var biometryLabel = String(appLoc: "密码")
// MARK: -
/// UserDefaults( MeView @AppStorage key)
/// observable UI @AppStorage key
var enabled: Bool {
get { UserDefaults.standard.bool(forKey: Self.enabledKey) }
set { UserDefaults.standard.set(newValue, forKey: Self.enabledKey) }
}
private var lastBackgroundedAt: Date?
private var didColdLaunchLock = false
private var isAuthenticating = false
private init() {
refreshAvailability()
}
// MARK: -
/// /
func refreshAvailability() {
let ctx = LAContext()
var error: NSError?
// .deviceOwnerAuthentication: true( + )
biometryAvailable = ctx.canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
// biometryType canEvaluatePolicy
switch ctx.biometryType {
case .faceID: biometryLabel = "Face ID"
case .touchID: biometryLabel = "Touch ID"
default: biometryLabel = String(appLoc: "密码")
}
}
// MARK: - ( AppLockContainer )
/// :
func handleAppear() {
refreshAvailability()
guard enabled, !didColdLaunchLock else { return }
didColdLaunchLock = true
isLocked = true
Task { await authenticate() }
}
/// scenePhase
func handleScenePhase(_ phase: ScenePhase) {
switch phase {
case .inactive:
// / :()
showsPrivacyCover = enabled && !isLocked
case .background:
lastBackgroundedAt = Date()
showsPrivacyCover = enabled
case .active:
showsPrivacyCover = false
if enabled, !isLocked,
let since = lastBackgroundedAt,
Date().timeIntervalSince(since) > Self.gracePeriod {
isLocked = true
}
if isLocked { Task { await authenticate() } }
lastBackgroundedAt = nil
@unknown default:
break
}
}
// MARK: -
/// ;/ `isAuthenticating` ,
/// onAppear
func authenticate() async {
guard isLocked, !isAuthenticating else { return }
isAuthenticating = true
defer { isAuthenticating = false }
let ctx = LAContext()
ctx.localizedFallbackTitle = String(appLoc: "输入密码")
do {
let ok = try await ctx.evaluatePolicy(
.deviceOwnerAuthentication,
localizedReason: String(appLoc: "解锁康康,查看你的健康档案")
)
if ok { isLocked = false }
} catch {
// /:, UI
}
}
// MARK: - (MeView )
/// :( + ), `enabled`
///
@discardableResult
func enableWithAuth() async -> Bool {
let ctx = LAContext()
ctx.localizedFallbackTitle = String(appLoc: "输入密码")
do {
let ok = try await ctx.evaluatePolicy(
.deviceOwnerAuthentication,
localizedReason: String(appLoc: "验证你本人,开启 Face ID 启动锁")
)
if ok {
enabled = true
return true
}
} catch {
// /:
}
return false
}
/// :( App )
func disable() {
enabled = false
}
}

View File

@@ -0,0 +1,31 @@
import SwiftUI
/// `RootView` : scenePhase, /
/// RootView (线 §10.7 Tab )
///
/// (KangkangApp):`AppLockContainer { RootView() }`
struct AppLockContainer<Content: View>: View {
@ViewBuilder var content: () -> Content
@Environment(\.scenePhase) private var scenePhase
@State private var appLock = AppLock.shared
var body: some View {
content()
.overlay {
if appLock.isLocked {
LockScreenView()
.transition(.opacity)
} else if appLock.showsPrivacyCover {
// :,
PrivacyCoverView()
}
}
// ;
.animation(.easeInOut(duration: 0.2), value: appLock.isLocked)
.onAppear { appLock.handleAppear() }
.onChange(of: scenePhase) { _, newPhase in
appLock.handleScenePhase(newPhase)
}
}
}

View File

@@ -0,0 +1,94 @@
import SwiftUI
/// :,onAppear ;/,
struct LockScreenView: View {
@State private var appLock = AppLock.shared
/// /
private var glyph: String {
switch appLock.biometryLabel {
case "Face ID": return "faceid"
case "Touch ID": return "touchid"
default: return "lock.fill"
}
}
var body: some View {
ZStack {
Tj.Palette.sand.ignoresSafeArea()
VStack(spacing: 18) {
Spacer()
ZStack {
Circle()
.fill(Tj.Palette.paper)
.overlay(Circle().strokeBorder(Tj.Palette.line, lineWidth: 1))
Image(systemName: "lock.fill")
.font(.system(size: 34))
.foregroundStyle(Tj.Palette.ink)
}
.frame(width: 92, height: 92)
.shadow(color: Tj.Palette.ink.opacity(0.06), radius: 12, y: 4)
VStack(spacing: 6) {
Text("康康 已锁定")
.font(.tjH2())
.foregroundStyle(Tj.Palette.text)
Text("你的健康档案已加密保护")
.font(.system(size: 13))
.foregroundStyle(Tj.Palette.text3)
}
Spacer()
Button {
Task { await appLock.authenticate() }
} label: {
Label("\(appLock.biometryLabel) 解锁", systemImage: glyph)
.frame(maxWidth: .infinity)
}
.buttonStyle(TjPrimaryButton(height: 52, fontSize: 16))
.padding(.horizontal, 40)
.padding(.bottom, 48)
}
}
.onAppear {
Task { await appLock.authenticate() }
}
}
}
/// : / ,
/// ,
struct PrivacyCoverView: View {
var body: some View {
ZStack {
Tj.Palette.sand.ignoresSafeArea()
VStack(spacing: 14) {
ZStack {
Circle()
.fill(Tj.Palette.paper)
.overlay(Circle().strokeBorder(Tj.Palette.line, lineWidth: 1))
Image(systemName: "heart.text.square.fill")
.font(.system(size: 30))
.foregroundStyle(Tj.Palette.ink)
}
.frame(width: 80, height: 80)
Text("康康")
.font(.tjH2())
.foregroundStyle(Tj.Palette.text)
}
}
}
}
#Preview("锁屏") {
LockScreenView()
}
#Preview("隐私遮罩") {
PrivacyCoverView()
}