Skip to content

Commit 1fd4202

Browse files
committed
本地化:统一使用 .localized 进行字符串本地化并更新本地化资源。
1 parent 635263e commit 1fd4202

9 files changed

Lines changed: 4480 additions & 1612 deletions

AppPorts/AboutView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ struct AboutView: View {
4242

4343
// 2. 文字信息
4444
VStack(spacing: 6) {
45-
Text("AppPorts")
45+
Text("AppPorts".localized)
4646
.font(.title)
4747
.fontWeight(.bold)
4848

49-
Text("Version \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0")".localized)
49+
Text(String(format: "Version %@".localized, Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "1.0"))
5050
.font(.subheadline)
5151
.foregroundColor(.secondary)
5252
}
5353
.padding(.bottom, 8)
5454

5555
// 3. 描述文案
56-
Text("感谢你使用本工具,外置硬盘拯救世界!")
56+
Text("感谢你使用本工具,外置硬盘拯救世界!".localized)
5757
.font(.body)
5858
.multilineTextAlignment(.center)
5959
.foregroundColor(.primary.opacity(0.9))
@@ -63,14 +63,14 @@ struct AboutView: View {
6363
// 4. 链接区域 (垂直排列)
6464
VStack(spacing: 12) {
6565
LinkButton(
66-
titleKey: "个人网站",
66+
title: "个人网站".localized,
6767
icon: "globe",
6868
url: "https://www.shimoko.com"
6969
)
7070

7171

7272
LinkButton(
73-
titleKey: "项目地址",
73+
title: "项目地址".localized,
7474
icon: "terminal.fill",
7575
url: "https://github.com/wzh4869/AppPorts"
7676
)
@@ -80,7 +80,7 @@ struct AboutView: View {
8080
Spacer()
8181

8282
// 5. 关闭按钮
83-
Button("关闭") {
83+
Button("关闭".localized) {
8484
dismiss()
8585
}
8686
.buttonStyle(.borderedProminent)
@@ -109,7 +109,7 @@ struct AboutView: View {
109109
/// - Note: 使用 SwiftUI Link 组件,点击自动在浏览器打开
110110
struct LinkButton: View {
111111
/// 按钮显示文本(本地化字符串键)
112-
let titleKey: LocalizedStringKey
112+
let title: String
113113

114114
/// SF Symbols 图标名称
115115
let icon: String
@@ -126,7 +126,7 @@ struct LinkButton: View {
126126
Image(systemName: icon)
127127
.frame(width: 20)
128128

129-
Text(titleKey)
129+
Text(title)
130130
.fontWeight(.medium)
131131

132132
Spacer()

AppPorts/Appports.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ struct AppMoverApp: App {
132132
Divider()
133133

134134
// 日志开关
135-
Button(AppLogger.shared.isLoggingEnabled ? "✅ 启用日志记录" : "启用日志记录") {
135+
Button(AppLogger.shared.isLoggingEnabled ? "" + "启用日志记录".localized : "启用日志记录".localized) {
136136
AppLogger.shared.isLoggingEnabled.toggle()
137137
}
138138

139139
// 日志大小设置
140-
Menu("最大日志大小") {
140+
Menu("最大日志大小".localized) {
141141
let currentSize = AppLogger.shared.maxLogSize
142142

143143
Button(currentSize == 1 * 1024 * 1024 ? "✅ 1 MB" : "1 MB") {

AppPorts/ContentView.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct ContentView: View {
7878
HStack(spacing: 8) {
7979
Image(systemName: "magnifyingglass")
8080
.foregroundColor(.secondary)
81-
TextField("搜索应用 (本地 / 外部)...", text: $searchText)
81+
TextField("搜索应用 (本地 / 外部)...".localized, text: $searchText)
8282
.textFieldStyle(.plain)
8383
.font(.system(size: 13))
8484
}
@@ -92,23 +92,23 @@ struct ContentView: View {
9292

9393
// Sort Button
9494
Menu {
95-
Picker("排序方式", selection: $sortOption) {
96-
Text("按名称").tag(SortOption.name)
97-
Text("按大小").tag(SortOption.size)
95+
Picker("排序方式".localized, selection: $sortOption) {
96+
Text("按名称".localized).tag(SortOption.name)
97+
Text("按大小".localized).tag(SortOption.size)
9898
}
9999
} label: {
100-
Label("排序", systemImage: "line.3.horizontal.decrease.circle")
100+
Label("排序".localized, systemImage: "line.3.horizontal.decrease.circle")
101101
}
102102
.menuStyle(.borderlessButton)
103103
.fixedSize()
104104
.help("排序方式")
105105

106106
// App Store Settings Button
107107
Button(action: { showAppStoreSettings = true }) {
108-
Label("设置", systemImage: "gearshape")
108+
Label("设置".localized, systemImage: "gearshape")
109109
}
110110
.buttonStyle(.borderless)
111-
.help("App Store 应用迁移设置")
111+
.help("App Store 应用迁移设置".localized)
112112
}
113113
.padding(.horizontal, 20)
114114
.padding(.vertical, 12)
@@ -184,12 +184,12 @@ struct ContentView: View {
184184
.foregroundColor(.accentColor)
185185

186186
// 【修复点 2】直接使用字面量,SwiftUI 会自动翻译
187-
Text("请选择外部存储路径")
187+
Text("请选择外部存储路径".localized)
188188
.font(.title3)
189189
.fontWeight(.medium)
190190
.foregroundColor(.secondary)
191191

192-
Button("选择文件夹") { openPanelForExternalDrive() }
192+
Button("选择文件夹".localized) { openPanelForExternalDrive() }
193193
.buttonStyle(.borderedProminent)
194194
.controlSize(.large)
195195
}
@@ -294,18 +294,18 @@ struct ContentView: View {
294294
scanExternalApps()
295295
}
296296

297-
.alert(LocalizedStringKey(alertTitle), isPresented: $showAlert) {
298-
Button("好的", role: .cancel) { }
297+
.alert(LocalizedStringKey(alertTitle.localized), isPresented: $showAlert) {
298+
Button("好的".localized, role: .cancel) { }
299299
} message: {
300-
Text(LocalizedStringKey(alertMessage))
300+
Text(LocalizedStringKey(alertMessage.localized))
301301
}
302-
.alert("发现新版本", isPresented: $showUpdateAlert) {
303-
Button("前往下载", role: .none) {
302+
.alert("发现新版本".localized, isPresented: $showUpdateAlert) {
303+
Button("前往下载".localized, role: .none) {
304304
if let url = updateURL { NSWorkspace.shared.open(url) }
305305
}
306-
Button("以后再说", role: .cancel) {}
306+
Button("以后再说".localized, role: .cancel) {}
307307
} message: {
308-
Text(alertMessage)
308+
Text(alertMessage.localized)
309309
}
310310
// App Store 应用迁移确认弹窗
311311
.alert("App Store 应用".localized, isPresented: $showAppStoreConfirm) {
@@ -403,7 +403,7 @@ struct ContentView: View {
403403

404404
VStack(alignment: .leading, spacing: 4) {
405405
// 将传入的 title 字符串转换为 Key,触发翻译
406-
Text(LocalizedStringKey(title))
406+
Text(title.localized)
407407
.font(.headline)
408408

409409
Text(subtitle)
@@ -417,7 +417,7 @@ struct ContentView: View {
417417

418418
if let btnText = actionButtonText, let action = onAction {
419419

420-
Button(LocalizedStringKey(btnText), action: action)
420+
Button(btnText.localized, action: action)
421421
.controlSize(.small)
422422
.buttonStyle(.bordered)
423423
}
@@ -455,7 +455,7 @@ struct ContentView: View {
455455
Spacer()
456456
Button(action: action) {
457457
HStack(spacing: 8) {
458-
Text(LocalizedStringKey(title))
458+
Text(title.localized)
459459
.fontWeight(.semibold)
460460
Image(systemName: icon)
461461
}
@@ -483,7 +483,7 @@ struct ContentView: View {
483483
.font(.largeTitle)
484484
.foregroundColor(.secondary.opacity(0.3))
485485

486-
Text(LocalizedStringKey(text))
486+
Text(text.localized)
487487
.foregroundColor(.secondary.opacity(0.7))
488488
}
489489
.accessibilityElement(children: .combine)

0 commit comments

Comments
 (0)