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:
@@ -6,38 +6,37 @@ struct SelectedDay: Identifiable, Hashable {
|
||||
var id: TimeInterval { date.timeIntervalSince1970 }
|
||||
}
|
||||
|
||||
struct DayDetailSheet: View {
|
||||
@Environment(\.modelContext) private var ctx
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
// MARK: - DayDetailContent(可 inline 或入 sheet)
|
||||
|
||||
/// 选中日详情的核心渲染。无 sheet 外壳,可同时被 TrendsView inline 使用,也能被 sheet 包。
|
||||
struct DayDetailContent: View {
|
||||
let date: Date
|
||||
let indicators: [Indicator]
|
||||
let reports: [Report]
|
||||
let diaries: [DiaryEntry]
|
||||
let symptoms: [Symptom]
|
||||
/// 是否显示日期 header(inline 时通常自带 header,sheet 模式让 DayDetailSheet 自己画)
|
||||
var showHeader: Bool = true
|
||||
|
||||
@State private var endingSymptom: Symptom?
|
||||
|
||||
private let calendar: Calendar = {
|
||||
var c = Calendar(identifier: .gregorian)
|
||||
c.locale = Locale(identifier: "zh_CN")
|
||||
c.locale = Locale.current
|
||||
return c
|
||||
}()
|
||||
|
||||
// MARK: - 当日数据筛选
|
||||
// MARK: 当日筛选
|
||||
|
||||
private var dayIndicators: [Indicator] {
|
||||
indicators.filter { calendar.isDate($0.capturedAt, inSameDayAs: date) }
|
||||
}
|
||||
|
||||
private var dayReports: [Report] {
|
||||
reports.filter { calendar.isDate($0.reportDate, inSameDayAs: date) }
|
||||
}
|
||||
|
||||
private var dayDiaries: [DiaryEntry] {
|
||||
diaries.filter { calendar.isDate($0.createdAt, inSameDayAs: date) }
|
||||
}
|
||||
|
||||
private var daySymptoms: [(symptom: Symptom, state: SymptomDayState)] {
|
||||
symptoms.compactMap { s in
|
||||
let start = calendar.startOfDay(for: s.startedAt)
|
||||
@@ -52,90 +51,54 @@ struct DayDetailSheet: View {
|
||||
return (s, state)
|
||||
}
|
||||
}
|
||||
|
||||
private var totalCount: Int {
|
||||
dayIndicators.count + dayReports.count + dayDiaries.count + daySymptoms.count
|
||||
}
|
||||
|
||||
// MARK: - body
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
Capsule()
|
||||
.fill(Tj.Palette.line)
|
||||
.frame(width: 40, height: 4)
|
||||
.padding(.top, 10)
|
||||
.padding(.bottom, 14)
|
||||
|
||||
header
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 12)
|
||||
|
||||
VStack(alignment: .leading, spacing: 14) {
|
||||
if showHeader { header }
|
||||
if totalCount == 0 {
|
||||
emptyState
|
||||
} else {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack(alignment: .leading, spacing: 18) {
|
||||
if !daySymptoms.isEmpty {
|
||||
section("症状", count: daySymptoms.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(daySymptoms, id: \.symptom.id) { item in
|
||||
symptomRow(item.symptom, state: item.state)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !dayIndicators.isEmpty {
|
||||
section("指标", count: dayIndicators.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(dayIndicators) { i in
|
||||
indicatorRow(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !dayReports.isEmpty {
|
||||
section("报告", count: dayReports.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(dayReports) { r in
|
||||
reportRow(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !dayDiaries.isEmpty {
|
||||
section("日记", count: dayDiaries.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(dayDiaries) { d in
|
||||
diaryRow(d)
|
||||
}
|
||||
}
|
||||
if !daySymptoms.isEmpty {
|
||||
section(String(appLoc: "症状"), count: daySymptoms.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(daySymptoms, id: \.symptom.id) { item in
|
||||
symptomRow(item.symptom, state: item.state)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 24)
|
||||
}
|
||||
if !dayIndicators.isEmpty {
|
||||
section(String(appLoc: "指标"), count: dayIndicators.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(dayIndicators) { i in indicatorRow(i) }
|
||||
}
|
||||
}
|
||||
}
|
||||
if !dayReports.isEmpty {
|
||||
section(String(appLoc: "报告"), count: dayReports.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(dayReports) { r in reportRow(r) }
|
||||
}
|
||||
}
|
||||
}
|
||||
if !dayDiaries.isEmpty {
|
||||
section(String(appLoc: "日记"), count: dayDiaries.count) {
|
||||
VStack(spacing: 8) {
|
||||
ForEach(dayDiaries) { d in diaryRow(d) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.background(
|
||||
Tj.Palette.sand
|
||||
.clipShape(RoundedRectangle(cornerRadius: Tj.Radius.xl, style: .continuous))
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
)
|
||||
.presentationDetents([.medium, .large])
|
||||
.presentationDragIndicator(.hidden)
|
||||
.presentationBackground(Tj.Palette.sand)
|
||||
.presentationCornerRadius(Tj.Radius.xl)
|
||||
.sheet(item: $endingSymptom) { sym in
|
||||
SymptomEndSheet(symptom: sym)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - header
|
||||
// MARK: header
|
||||
|
||||
private var header: some View {
|
||||
HStack(alignment: .firstTextBaseline) {
|
||||
@@ -145,7 +108,7 @@ struct DayDetailSheet: View {
|
||||
.tracking(0.5)
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Text(dayLabel)
|
||||
.font(.tjTitle(28))
|
||||
.font(.tjTitle(22))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
}
|
||||
Spacer()
|
||||
@@ -158,27 +121,18 @@ struct DayDetailSheet: View {
|
||||
}
|
||||
|
||||
private var dateLine: String {
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "zh_CN")
|
||||
f.dateFormat = "yyyy 年"
|
||||
return f.string(from: date) + " · " + weekdayLabel
|
||||
date.formatted(.dateTime.year()) + " · " + weekdayLabel
|
||||
}
|
||||
|
||||
private var dayLabel: String {
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "zh_CN")
|
||||
f.dateFormat = "M 月 d 日"
|
||||
return f.string(from: date)
|
||||
date.formatted(.dateTime.month().day())
|
||||
}
|
||||
|
||||
private var weekdayLabel: String {
|
||||
let f = DateFormatter()
|
||||
f.locale = Locale(identifier: "zh_CN")
|
||||
f.dateFormat = "EEEE"
|
||||
return f.string(from: date)
|
||||
date.formatted(.dateTime.weekday(.wide))
|
||||
}
|
||||
|
||||
// MARK: - section
|
||||
// MARK: section helper
|
||||
|
||||
private func section<Content: View>(_ title: String,
|
||||
count: Int,
|
||||
@@ -198,27 +152,30 @@ struct DayDetailSheet: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - rows
|
||||
// MARK: rows
|
||||
|
||||
private func symptomRow(_ s: Symptom, state: SymptomDayState) -> some View {
|
||||
HStack(spacing: 12) {
|
||||
Capsule()
|
||||
.fill(severityColor(s.severity))
|
||||
.frame(width: 4, height: 36)
|
||||
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
HStack(spacing: 6) {
|
||||
Text(s.name)
|
||||
.font(.system(size: 15, weight: .semibold))
|
||||
.foregroundStyle(Tj.Palette.text)
|
||||
stateBadge(state, isOngoing: s.isOngoing)
|
||||
Text(state.badge)
|
||||
.font(.system(size: 10, weight: .semibold))
|
||||
.foregroundStyle(state.badgeFg)
|
||||
.padding(.horizontal, 6)
|
||||
.padding(.vertical, 2)
|
||||
.background(Capsule().fill(state.badgeBg))
|
||||
}
|
||||
Text("\(state.subtitle) · 持续 \(formatDuration(s.duration))")
|
||||
.font(.system(size: 11))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
}
|
||||
Spacer(minLength: 6)
|
||||
|
||||
if s.isOngoing {
|
||||
Button {
|
||||
endingSymptom = s
|
||||
@@ -237,15 +194,6 @@ struct DayDetailSheet: View {
|
||||
.tjCard(bordered: true)
|
||||
}
|
||||
|
||||
private func stateBadge(_ state: SymptomDayState, isOngoing: Bool) -> some View {
|
||||
Text(state.badge)
|
||||
.font(.system(size: 10, weight: .semibold))
|
||||
.foregroundStyle(state.badgeFg)
|
||||
.padding(.horizontal, 6)
|
||||
.padding(.vertical, 2)
|
||||
.background(Capsule().fill(state.badgeBg))
|
||||
}
|
||||
|
||||
private func indicatorRow(_ i: Indicator) -> some View {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
@@ -256,7 +204,6 @@ struct DayDetailSheet: View {
|
||||
.foregroundStyle(indicatorAccent(i))
|
||||
}
|
||||
.frame(width: 32, height: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(i.name)
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
@@ -269,7 +216,6 @@ struct DayDetailSheet: View {
|
||||
}
|
||||
}
|
||||
Spacer(minLength: 6)
|
||||
|
||||
Text("\(i.value) \(i.unit)\(arrow(i))")
|
||||
.font(.system(size: 13, weight: .semibold, design: .monospaced))
|
||||
.foregroundStyle(i.status == .normal ? Tj.Palette.text2 : Tj.Palette.brick)
|
||||
@@ -291,7 +237,6 @@ struct DayDetailSheet: View {
|
||||
.foregroundStyle(Tj.Palette.ink2)
|
||||
}
|
||||
.frame(width: 32, height: 32)
|
||||
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(r.title)
|
||||
.font(.system(size: 14, weight: .medium))
|
||||
@@ -331,23 +276,19 @@ struct DayDetailSheet: View {
|
||||
.tjCard(bordered: true)
|
||||
}
|
||||
|
||||
// MARK: - empty
|
||||
|
||||
private var emptyState: some View {
|
||||
VStack(spacing: 12) {
|
||||
Spacer(minLength: 16)
|
||||
TjPlaceholder(label: "这一天还没有记录")
|
||||
.frame(width: 220, height: 120)
|
||||
VStack(spacing: 8) {
|
||||
TjPlaceholder(label: String(appLoc: "这一天还没有记录"))
|
||||
.frame(height: 90)
|
||||
.frame(maxWidth: 240)
|
||||
Text("点底部 + 号可以补一条")
|
||||
.font(.system(size: 12))
|
||||
.font(.system(size: 11))
|
||||
.foregroundStyle(Tj.Palette.text3)
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
// MARK: - utils
|
||||
|
||||
private func severityColor(_ value: Int) -> Color {
|
||||
switch value {
|
||||
case 1, 2: return Tj.Palette.leaf
|
||||
@@ -369,22 +310,65 @@ struct DayDetailSheet: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Sheet wrapper(保留;现在 TrendsView 走 inline,但其他入口可能用)
|
||||
|
||||
struct DayDetailSheet: View {
|
||||
let date: Date
|
||||
let indicators: [Indicator]
|
||||
let reports: [Report]
|
||||
let diaries: [DiaryEntry]
|
||||
let symptoms: [Symptom]
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
Capsule()
|
||||
.fill(Tj.Palette.line)
|
||||
.frame(width: 40, height: 4)
|
||||
.padding(.top, 10)
|
||||
.padding(.bottom, 14)
|
||||
ScrollView(showsIndicators: false) {
|
||||
DayDetailContent(
|
||||
date: date,
|
||||
indicators: indicators,
|
||||
reports: reports,
|
||||
diaries: diaries,
|
||||
symptoms: symptoms,
|
||||
showHeader: true
|
||||
)
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.bottom, 24)
|
||||
}
|
||||
}
|
||||
.background(
|
||||
Tj.Palette.sand
|
||||
.clipShape(RoundedRectangle(cornerRadius: Tj.Radius.xl, style: .continuous))
|
||||
.ignoresSafeArea(edges: .bottom)
|
||||
)
|
||||
.presentationDetents([.medium, .large])
|
||||
.presentationDragIndicator(.hidden)
|
||||
.presentationBackground(Tj.Palette.sand)
|
||||
.presentationCornerRadius(Tj.Radius.xl)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SymptomDayState
|
||||
|
||||
enum SymptomDayState {
|
||||
case startedToday, ongoing, endedToday
|
||||
|
||||
var subtitle: String {
|
||||
switch self {
|
||||
case .startedToday: return "今天开始"
|
||||
case .ongoing: return "进行中"
|
||||
case .endedToday: return "今天结束"
|
||||
case .startedToday: return String(appLoc: "今天开始")
|
||||
case .ongoing: return String(appLoc: "进行中")
|
||||
case .endedToday: return String(appLoc: "今天结束")
|
||||
}
|
||||
}
|
||||
|
||||
var badge: String {
|
||||
switch self {
|
||||
case .startedToday: return "开始"
|
||||
case .ongoing: return "持续"
|
||||
case .endedToday: return "结束"
|
||||
case .startedToday: return String(appLoc: "开始")
|
||||
case .ongoing: return String(appLoc: "持续")
|
||||
case .endedToday: return String(appLoc: "结束")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user