-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathChatSection.swift
More file actions
79 lines (69 loc) · 2.28 KB
/
ChatSection.swift
File metadata and controls
79 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import SwiftUI
import ComposableArchitecture
struct ChatSection: View {
var body: some View {
SettingsSection(title: "Chat Settings") {
VStack(spacing: 10) {
// Response language picker
ResponseLanguageSetting()
}
.padding(10)
}
}
}
struct ResponseLanguageSetting: View {
@AppStorage(\.chatResponseLocale) var chatResponseLocale
// Locale codes mapped to language display names
// reference: https://code.visualstudio.com/docs/configure/locales#_available-locales
private let localeLanguageMap: [String: String] = [
"en": "English",
"zh-cn": "Chinese, Simplified",
"zh-tw": "Chinese, Traditional",
"fr": "French",
"de": "German",
"it": "Italian",
"es": "Spanish",
"ja": "Japanese",
"ko": "Korean",
"ru": "Russian",
"pt-br": "Portuguese (Brazil)",
"tr": "Turkish",
"pl": "Polish",
"cs": "Czech",
"hu": "Hungarian"
]
var selectedLanguage: String {
if chatResponseLocale == "" {
return "English"
}
return localeLanguageMap[chatResponseLocale] ?? "English"
}
// Display name to locale code mapping (for the picker UI)
var sortedLanguageOptions: [(displayName: String, localeCode: String)] {
localeLanguageMap.map { (displayName: $0.value, localeCode: $0.key) }
.sorted { $0.displayName < $1.displayName }
}
var body: some View {
WithPerceptionTracking {
HStack {
VStack(alignment: .leading) {
Text("Response Language")
.font(.body)
Text("This change applies only to new chat sessions. Existing ones won’t be impacted.")
.font(.footnote)
}
Spacer()
Picker("", selection: $chatResponseLocale) {
ForEach(sortedLanguageOptions, id: \.localeCode) { option in
Text(option.displayName).tag(option.localeCode)
}
}
.frame(maxWidth: 200, alignment: .leading)
}
}
}
}
#Preview {
ChatSection()
.frame(width: 600)
}