Skip to content

Commit 35d26b9

Browse files
committed
feat: Complete Chinese localization and fix infrastructure
1 parent 11edd39 commit 35d26b9

File tree

20 files changed

+673
-157
lines changed

20 files changed

+673
-157
lines changed

Ice.xcodeproj/project.pbxproj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
knownRegions = (
119119
en,
120120
Base,
121+
"zh-Hans",
121122
);
122123
mainGroup = 716683212A767E6A006ABF84;
123124
packageReferences = (
@@ -306,12 +307,13 @@
306307
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
307308
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
308309
CODE_SIGN_ENTITLEMENTS = Ice/Ice.entitlements;
309-
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
310+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
310311
CODE_SIGN_STYLE = Automatic;
311312
COMBINE_HIDPI_IMAGES = YES;
312313
CURRENT_PROJECT_VERSION = 1117;
313314
DEAD_CODE_STRIPPING = YES;
314315
DEVELOPMENT_ASSET_PATHS = "";
316+
DEVELOPMENT_TEAM = "";
315317
ENABLE_HARDENED_RUNTIME = YES;
316318
ENABLE_PREVIEWS = YES;
317319
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -338,12 +340,13 @@
338340
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
339341
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
340342
CODE_SIGN_ENTITLEMENTS = Ice/Ice.entitlements;
341-
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
343+
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
342344
CODE_SIGN_STYLE = Automatic;
343345
COMBINE_HIDPI_IMAGES = YES;
344346
CURRENT_PROJECT_VERSION = 1117;
345347
DEAD_CODE_STRIPPING = YES;
346348
DEVELOPMENT_ASSET_PATHS = "";
349+
DEVELOPMENT_TEAM = "";
347350
ENABLE_HARDENED_RUNTIME = YES;
348351
ENABLE_PREVIEWS = YES;
349352
ENABLE_USER_SCRIPT_SANDBOXING = NO;

Ice/Main/Navigation/NavigationIdentifiers/SettingsNavigationIdentifier.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Ice
44
//
55

6+
import SwiftUI
7+
68
/// An identifier used for navigation in the settings interface.
79
enum SettingsNavigationIdentifier: String, NavigationIdentifier {
810
case general = "General"
@@ -11,4 +13,19 @@ enum SettingsNavigationIdentifier: String, NavigationIdentifier {
1113
case hotkeys = "Hotkeys"
1214
case advanced = "Advanced"
1315
case about = "About"
16+
17+
var localized: LocalizedStringKey {
18+
switch self {
19+
case .general: "General"
20+
case .menuBarLayout: "Menu Bar Layout"
21+
case .menuBarAppearance: "Menu Bar Appearance"
22+
case .hotkeys: "Hotkeys"
23+
case .advanced: "Advanced"
24+
case .about: "About"
25+
}
26+
}
27+
28+
func localized(for language: Language) -> String {
29+
rawValue.localized(for: language)
30+
}
1431
}

Ice/MenuBar/Appearance/MenuBarAppearanceEditor/MenuBarAppearanceEditor.swift

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ struct MenuBarAppearanceEditor: View {
3636
private var stackHeader: some View {
3737
if case .popover(let closePopover) = location {
3838
ZStack {
39-
Text("Menu Bar Appearance")
39+
Text(verbatim: "Menu Bar Appearance".localized(for: appState.settingsManager.generalSettingsManager.language))
4040
.font(.title2)
4141
.frame(maxWidth: .infinity, alignment: .center)
42-
Button("Done", action: closePopover)
42+
Button {
43+
closePopover()
44+
} label: {
45+
Text(verbatim: "Done".localized(for: appState.settingsManager.generalSettingsManager.language))
46+
}
4347
.controlSize(.large)
4448
.frame(maxWidth: .infinity, alignment: .trailing)
4549
}
@@ -68,7 +72,10 @@ struct MenuBarAppearanceEditor: View {
6872
} else {
6973
StaticPartialEditor()
7074
}
71-
IceSection("Menu Bar Shape") {
75+
IceSection(header: {
76+
Text(verbatim: "Menu Bar Shape".localized(for: appState.settingsManager.generalSettingsManager.language))
77+
.font(.headline)
78+
}) {
7279
shapePicker
7380
isInset
7481
}
@@ -79,7 +86,7 @@ struct MenuBarAppearanceEditor: View {
7986
font: .callout.bold()
8087
) {
8188
Label {
82-
Text("Tip: you can also edit these settings by right-clicking in an empty area of the menu bar")
89+
Text(verbatim: "Tip: you can also edit these settings by right-clicking in an empty area of the menu bar".localized(for: appState.settingsManager.generalSettingsManager.language))
8390
} icon: {
8491
Image(systemName: "lightbulb")
8592
}
@@ -90,8 +97,10 @@ struct MenuBarAppearanceEditor: View {
9097
!appState.menuBarManager.isMenuBarHiddenBySystemUserDefaults,
9198
appearanceManager.configuration != .defaultConfiguration
9299
{
93-
Button("Reset") {
100+
Button {
94101
appearanceManager.configuration = .defaultConfiguration
102+
} label: {
103+
Text(verbatim: "Reset".localized(for: appState.settingsManager.generalSettingsManager.language))
95104
}
96105
.controlSize(.large)
97106
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
@@ -101,13 +110,17 @@ struct MenuBarAppearanceEditor: View {
101110

102111
@ViewBuilder
103112
private var isDynamicToggle: some View {
104-
Toggle("Use dynamic appearance", isOn: appearanceManager.bindings.configuration.isDynamic)
105-
.annotation("Apply different settings based on the current system appearance")
113+
Toggle(isOn: appearanceManager.bindings.configuration.isDynamic) {
114+
Text(verbatim: "Use dynamic appearance".localized(for: appState.settingsManager.generalSettingsManager.language))
115+
}
116+
.annotation {
117+
Text(verbatim: "Apply different settings based on the current system appearance".localized(for: appState.settingsManager.generalSettingsManager.language))
118+
}
106119
}
107120

108121
@ViewBuilder
109122
private var cannotEdit: some View {
110-
Text("Ice cannot edit the appearance of automatically hidden menu bars")
123+
Text(verbatim: "Ice cannot edit the appearance of automatically hidden menu bars".localized(for: appState.settingsManager.generalSettingsManager.language))
111124
.font(.title3)
112125
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
113126
}
@@ -121,16 +134,16 @@ struct MenuBarAppearanceEditor: View {
121134
@ViewBuilder
122135
private var isInset: some View {
123136
if appearanceManager.configuration.shapeKind != .none {
124-
Toggle(
125-
"Use inset shape on screens with notch",
126-
isOn: appearanceManager.bindings.configuration.isInset
127-
)
137+
Toggle(isOn: appearanceManager.bindings.configuration.isInset) {
138+
Text(verbatim: "Use inset shape on screens with notch".localized(for: appState.settingsManager.generalSettingsManager.language))
139+
}
128140
}
129141
}
130142
}
131143

132144
private struct UnlabeledPartialEditor: View {
133145
@Binding var configuration: MenuBarAppearancePartialConfiguration
146+
@EnvironmentObject var appState: AppState
134147

135148
var body: some View {
136149
IceSection {
@@ -146,12 +159,14 @@ private struct UnlabeledPartialEditor: View {
146159

147160
@ViewBuilder
148161
private var tintPicker: some View {
149-
IceLabeledContent("Tint") {
162+
IceLabeledContent {
150163
HStack {
151-
IcePicker("Tint", selection: $configuration.tintKind) {
164+
IcePicker(selection: $configuration.tintKind) {
152165
ForEach(MenuBarTintKind.allCases) { tintKind in
153166
Text(tintKind.localized).tag(tintKind)
154167
}
168+
} label: {
169+
Text(verbatim: "Tint".localized(for: appState.settingsManager.generalSettingsManager.language))
155170
}
156171
.labelsHidden()
157172

@@ -174,28 +189,36 @@ private struct UnlabeledPartialEditor: View {
174189
}
175190
}
176191
.frame(height: 24)
192+
} label: {
193+
Text(verbatim: "Tint".localized(for: appState.settingsManager.generalSettingsManager.language))
177194
}
178195
}
179196

180197
@ViewBuilder
181198
private var shadowToggle: some View {
182-
Toggle("Shadow", isOn: $configuration.hasShadow)
199+
Toggle(isOn: $configuration.hasShadow) {
200+
Text(verbatim: "Shadow".localized(for: appState.settingsManager.generalSettingsManager.language))
201+
}
183202
}
184203

185204
@ViewBuilder
186205
private var borderToggle: some View {
187-
Toggle("Border", isOn: $configuration.hasBorder)
206+
Toggle(isOn: $configuration.hasBorder) {
207+
Text(verbatim: "Border".localized(for: appState.settingsManager.generalSettingsManager.language))
208+
}
188209
}
189210

190211
@ViewBuilder
191212
private var borderColor: some View {
192213
if configuration.hasBorder {
193-
IceLabeledContent("Border Color") {
214+
IceLabeledContent {
194215
CustomColorPicker(
195216
selection: $configuration.borderColor,
196217
supportsOpacity: true,
197218
mode: .crayon
198219
)
220+
} label: {
221+
Text(verbatim: "Border Color".localized(for: appState.settingsManager.generalSettingsManager.language))
199222
}
200223
}
201224
}
@@ -204,12 +227,13 @@ private struct UnlabeledPartialEditor: View {
204227
private var borderWidth: some View {
205228
if configuration.hasBorder {
206229
IcePicker(
207-
"Border Width",
208230
selection: $configuration.borderWidth
209231
) {
210232
Text("1").tag(1.0)
211233
Text("2").tag(2.0)
212234
Text("3").tag(3.0)
235+
} label: {
236+
Text(verbatim: "Border Width".localized(for: appState.settingsManager.generalSettingsManager.language))
213237
}
214238
}
215239
}
@@ -293,6 +317,8 @@ private struct PreviewButton: View {
293317
}
294318

295319
@EnvironmentObject var appearanceManager: MenuBarAppearanceManager
320+
@EnvironmentObject var appState: AppState
321+
296322

297323
@State private var frame = CGRect.zero
298324
@State private var isPressed = false
@@ -303,7 +329,7 @@ private struct PreviewButton: View {
303329
ZStack {
304330
DummyButton(isPressed: $isPressed)
305331
.allowsHitTesting(false)
306-
Text("Hold to Preview")
332+
Text(verbatim: "Hold to Preview".localized(for: appState.settingsManager.generalSettingsManager.language))
307333
.baselineOffset(1.5)
308334
.padding(.horizontal, 10)
309335
.contentShape(Rectangle())

Ice/MenuBar/Appearance/MenuBarAppearanceEditor/MenuBarShapePicker.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import SwiftUI
77

88
struct MenuBarShapePicker: View {
99
@EnvironmentObject var appearanceManager: MenuBarAppearanceManager
10+
@EnvironmentObject var appState: AppState
1011
@Environment(\.colorScheme) private var colorScheme
1112

1213
var body: some View {
@@ -16,25 +17,27 @@ struct MenuBarShapePicker: View {
1617

1718
@ViewBuilder
1819
private var shapeKindPicker: some View {
19-
IcePicker("Shape Kind", selection: appearanceManager.bindings.configuration.shapeKind) {
20+
IcePicker(selection: appearanceManager.bindings.configuration.shapeKind) {
2021
ForEach(MenuBarShapeKind.allCases, id: \.self) { shape in
2122
switch shape {
2223
case .none:
23-
Text("None").tag(shape)
24+
Text(verbatim: "None".localized(for: appState.settingsManager.generalSettingsManager.language)).tag(shape)
2425
case .full:
25-
Text("Full").tag(shape)
26+
Text(verbatim: "Full".localized(for: appState.settingsManager.generalSettingsManager.language)).tag(shape)
2627
case .split:
27-
Text("Split").tag(shape)
28+
Text(verbatim: "Split".localized(for: appState.settingsManager.generalSettingsManager.language)).tag(shape)
2829
}
2930
}
31+
} label: {
32+
Text(verbatim: "Shape Kind".localized(for: appState.settingsManager.generalSettingsManager.language))
3033
}
3134
}
3235

3336
@ViewBuilder
3437
private var exampleView: some View {
3538
switch appearanceManager.configuration.shapeKind {
3639
case .none:
37-
Text("No shape kind selected")
40+
Text(verbatim: "No shape kind selected".localized(for: appState.settingsManager.generalSettingsManager.language))
3841
.foregroundStyle(.secondary)
3942
.frame(maxWidth: .infinity, alignment: .center)
4043
case .full:

Ice/MenuBar/Search/MenuBarSearchPanel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private struct MenuBarSearchContentView: View {
260260
}
261261

262262
let headerItem = ListItem.header(id: .header(section)) {
263-
Text(section.displayString)
263+
Text(verbatim: section.displayString.localized(for: itemManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
264264
.fontWeight(.semibold)
265265
.foregroundStyle(.secondary)
266266
.frame(maxWidth: .infinity, alignment: .leading)

Ice/Permissions/PermissionsView.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ struct PermissionsView: View {
1111

1212
private var continueButtonText: LocalizedStringKey {
1313
if case .hasRequiredPermissions = permissionsManager.permissionsState {
14-
"Continue in Limited Mode"
14+
LocalizedStringKey("Continue in Limited Mode".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
1515
} else {
16-
"Continue"
16+
LocalizedStringKey("Continue".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
1717
}
1818
}
1919

@@ -58,7 +58,7 @@ struct PermissionsView: View {
5858
@ViewBuilder
5959
private var headerView: some View {
6060
Label {
61-
Text("Permissions")
61+
Text("Permissions".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
6262
.font(.system(size: 36))
6363
} icon: {
6464
if let nsImage = NSImage(named: NSImage.applicationIconName) {
@@ -74,8 +74,8 @@ struct PermissionsView: View {
7474
private var explanationView: some View {
7575
IceSection {
7676
VStack {
77-
Text("Ice needs permission to manage the menu bar.")
78-
Text("Absolutely no personal information is collected or stored.")
77+
Text("Ice needs permission to manage the menu bar.".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
78+
Text("Absolutely no personal information is collected or stored.".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
7979
.bold()
8080
.foregroundStyle(.red)
8181
}
@@ -108,7 +108,7 @@ struct PermissionsView: View {
108108
Button {
109109
NSApp.terminate(nil)
110110
} label: {
111-
Text("Quit")
111+
Text("Quit".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
112112
.frame(maxWidth: .infinity)
113113
}
114114
}
@@ -134,20 +134,20 @@ struct PermissionsView: View {
134134
private func permissionBox(_ permission: Permission) -> some View {
135135
IceSection {
136136
VStack(spacing: 10) {
137-
Text(permission.title)
137+
Text(permission.title.localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
138138
.font(.title)
139139
.underline()
140140

141141
VStack(spacing: 0) {
142-
Text("Ice needs this to:")
142+
Text("Ice needs this to:".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
143143
.font(.title3)
144144
.bold()
145145

146146
VStack(alignment: .leading) {
147147
ForEach(permission.details, id: \.self) { detail in
148148
HStack {
149149
Text("").bold()
150-
Text(detail)
150+
Text(detail.localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
151151
}
152152
}
153153
}
@@ -165,10 +165,10 @@ struct PermissionsView: View {
165165
}
166166
} label: {
167167
if permission.hasPermission {
168-
Text("Permission Granted")
168+
Text("Permission Granted".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
169169
.foregroundStyle(.green)
170170
} else {
171-
Text("Grant Permission")
171+
Text("Grant Permission".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
172172
}
173173
}
174174
.allowsHitTesting(!permission.hasPermission)
@@ -180,7 +180,7 @@ struct PermissionsView: View {
180180
font: .callout.bold()
181181
) {
182182
Label {
183-
Text("Ice can work in a limited mode without this permission.")
183+
Text("Ice can work in a limited mode without this permission.".localized(for: permissionsManager.appState?.settingsManager.generalSettingsManager.language ?? .english))
184184
} icon: {
185185
Image(systemName: "checkmark.shield")
186186
.foregroundStyle(.green)

0 commit comments

Comments
 (0)