Skip to content

Commit 4e6368f

Browse files
committed
feat: Enhance localization in Search and Content views
- Updated ContentView and SearchView to utilize localized strings for titles and prompts, improving user experience. - Added new localized strings for search-related UI elements in Discover.xcstrings, including search prompts, recent searches, and error messages. - Improved internationalization support by ensuring all relevant strings are properly localized for both English and Simplified Chinese.
1 parent 9399bce commit 4e6368f

File tree

4 files changed

+139
-12
lines changed

4 files changed

+139
-12
lines changed

NeoDB/NeoDB/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ContentView: View {
4141
}
4242
}
4343
.tabItem {
44-
Label("Search", systemImage: "magnifyingglass")
44+
Label(String(localized: "discover_search_title", table: "Discover"), systemImage: "magnifyingglass")
4545
}
4646
.tag(TabSection.search)
4747

Lines changed: 128 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,134 @@
11
{
22
"sourceLanguage" : "en",
33
"strings" : {
4-
4+
"discover_search_title" : {
5+
"localizations" : {
6+
"en" : {
7+
"stringUnit" : {
8+
"state" : "translated",
9+
"value" : "Search"
10+
}
11+
},
12+
"zh-Hans" : {
13+
"stringUnit" : {
14+
"state" : "translated",
15+
"value" : "搜索"
16+
}
17+
}
18+
}
19+
},
20+
"discover_search_prompt" : {
21+
"localizations" : {
22+
"en" : {
23+
"stringUnit" : {
24+
"state" : "translated",
25+
"value" : "Search books, movies, music..."
26+
}
27+
},
28+
"zh-Hans" : {
29+
"stringUnit" : {
30+
"state" : "translated",
31+
"value" : "搜索书籍、电影、音乐..."
32+
}
33+
}
34+
}
35+
},
36+
"discover_search_recent" : {
37+
"localizations" : {
38+
"en" : {
39+
"stringUnit" : {
40+
"state" : "translated",
41+
"value" : "Recent Searches"
42+
}
43+
},
44+
"zh-Hans" : {
45+
"stringUnit" : {
46+
"state" : "translated",
47+
"value" : "最近搜索"
48+
}
49+
}
50+
}
51+
},
52+
"discover_search_clear_all" : {
53+
"localizations" : {
54+
"en" : {
55+
"stringUnit" : {
56+
"state" : "translated",
57+
"value" : "Clear All"
58+
}
59+
},
60+
"zh-Hans" : {
61+
"stringUnit" : {
62+
"state" : "translated",
63+
"value" : "清除全部"
64+
}
65+
}
66+
}
67+
},
68+
"discover_search_no_results_title" : {
69+
"localizations" : {
70+
"en" : {
71+
"stringUnit" : {
72+
"state" : "translated",
73+
"value" : "No Results Found"
74+
}
75+
},
76+
"zh-Hans" : {
77+
"stringUnit" : {
78+
"state" : "translated",
79+
"value" : "未找到结果"
80+
}
81+
}
82+
}
83+
},
84+
"discover_search_no_results_description" : {
85+
"localizations" : {
86+
"en" : {
87+
"stringUnit" : {
88+
"state" : "translated",
89+
"value" : "Try different keywords or check your spelling"
90+
}
91+
},
92+
"zh-Hans" : {
93+
"stringUnit" : {
94+
"state" : "translated",
95+
"value" : "尝试使用不同的关键词或检查拼写"
96+
}
97+
}
98+
}
99+
},
100+
"discover_search_error_title" : {
101+
"localizations" : {
102+
"en" : {
103+
"stringUnit" : {
104+
"state" : "translated",
105+
"value" : "Something Went Wrong"
106+
}
107+
},
108+
"zh-Hans" : {
109+
"stringUnit" : {
110+
"state" : "translated",
111+
"value" : "出现错误"
112+
}
113+
}
114+
}
115+
},
116+
"discover_search_try_again" : {
117+
"localizations" : {
118+
"en" : {
119+
"stringUnit" : {
120+
"state" : "translated",
121+
"value" : "Try Again"
122+
}
123+
},
124+
"zh-Hans" : {
125+
"stringUnit" : {
126+
"state" : "translated",
127+
"value" : "重试"
128+
}
129+
}
130+
}
131+
}
5132
},
6133
"version" : "1.0"
7134
}

NeoDB/NeoDB/Views/Discover/SearchView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct SearchView: View {
1616

1717
var body: some View {
1818
searchContent
19-
.navigationTitle("Search")
19+
.navigationTitle(String(localized: "discover_search_title", table: "Discover"))
2020
.onAppear {
2121
viewModel.accountsManager = accountsManager
2222
Task {
@@ -67,7 +67,7 @@ struct SearchView: View {
6767
}
6868
}
6969
.listStyle(.plain)
70-
.searchable_iOS16(text: $viewModel.searchText, isPresented: $isSearchActive, prompt: "Search books, movies, music...")
70+
.searchable_iOS16(text: $viewModel.searchText, isPresented: $isSearchActive, prompt: String(localized: "discover_search_prompt", table: "Discover"))
7171
.onSubmit(of: .search) {
7272
Task {
7373
await viewModel.confirmSearch()
@@ -145,12 +145,12 @@ struct SearchView: View {
145145
viewModel.clearRecentSearches()
146146
}
147147
} label: {
148-
Text("Clear All")
148+
Text("discover_search_clear_all", tableName: "Discover")
149149
.font(.subheadline)
150150
}
151151
}
152152
} header: {
153-
Text("Recent Searches")
153+
Text("discover_search_recent", tableName: "Discover")
154154
}
155155
}
156156

@@ -200,9 +200,9 @@ struct SearchView: View {
200200
Image(systemName: "magnifyingglass")
201201
.font(.system(size: 36))
202202
.foregroundStyle(.secondary)
203-
Text("No Results Found")
203+
Text("discover_search_no_results_title", tableName: "Discover")
204204
.font(.headline)
205-
Text("Try different keywords or check your spelling")
205+
Text("discover_search_no_results_description", tableName: "Discover")
206206
.font(.subheadline)
207207
.foregroundStyle(.secondary)
208208
.multilineTextAlignment(.center)
@@ -265,13 +265,13 @@ struct SearchView: View {
265265
Image(systemName: "exclamationmark.triangle")
266266
.font(.system(size: 36))
267267
.foregroundStyle(.secondary)
268-
Text("Something Went Wrong")
268+
Text("discover_search_error_title", tableName: "Discover")
269269
.font(.headline)
270270
Text(error.localizedDescription)
271271
.font(.subheadline)
272272
.foregroundStyle(.secondary)
273273
.multilineTextAlignment(.center)
274-
Button("Try Again") {
274+
Button(String(localized: "discover_search_try_again", table: "Discover")) {
275275
Task {
276276
await viewModel.search()
277277
}

NeoDB/NeoDB/Views/Shared/Extension/Searchable.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import SwiftUI
99

1010
extension View {
11-
public func searchable_iOS16(text: Binding<String>, isPresented: Binding<Bool>, placement: SearchFieldPlacement = .automatic, prompt: LocalizedStringKey? = nil) -> some View {
11+
public func searchable_iOS16(text: Binding<String>, isPresented: Binding<Bool>, placement: SearchFieldPlacement = .automatic, prompt: String? = nil) -> some View {
1212
modifier(Searchable_iOS16(text: text, isPresented: isPresented, placement: placement, prompt: prompt))
1313
}
1414
}
@@ -18,7 +18,7 @@ public struct Searchable_iOS16: ViewModifier {
1818
@Binding var isPresented: Bool
1919
@State var legacyIsSearching = false
2020
var placement: SearchFieldPlacement = .automatic
21-
var prompt: LocalizedStringKey? = nil
21+
var prompt: String? = nil
2222

2323
public func body(content: Content) -> some View {
2424
#if os(watchOS) || os(tvOS)

0 commit comments

Comments
 (0)