Skip to content

Commit

Permalink
Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderLineChan committed Apr 24, 2023
1 parent d03a6b2 commit cd245fc
Show file tree
Hide file tree
Showing 17 changed files with 143 additions and 100 deletions.
4 changes: 2 additions & 2 deletions OSXChatGPT/OSXChatGPT/DataProvider/AIPromptViewMdoel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension AIPromptViewMdoel {

// 获取云端数据
HTTPClient.getPrompt { [weak self] datas, err in
print("云端数据请求成功")
// print("云端数据请求成功")
guard let self = self else { return }
var temp: [Prompt] = []
datas.forEach { json in
Expand Down Expand Up @@ -190,7 +190,7 @@ extension AIPromptViewMdoel {
self.allPrompts += temp
}
}else {
print("获取云端数据失败!!!需要更新token")
// print("获取云端数据失败!!!需要更新token")
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions OSXChatGPT/OSXChatGPT/DataProvider/ChatGPTManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ extension ChatGPTManager {
for try await line in stream {
await tempMessagePool.append(line: line)
let newMessage = await tempMessagePool.message
print("回复1:\(line)")
print("回复2:\(newMessage)")
// print("回复1:\(line)")
// print("回复2:\(newMessage)")
newMsg += newMessage
let res = ChatGPTResponse(request: request ,state: .replying, text: newMessage, stream: line)
complete?(res)
Expand Down
4 changes: 2 additions & 2 deletions OSXChatGPT/OSXChatGPT/DataProvider/KeyboardMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class KeyboardMonitor {
}
shiftKeyMonitor = NSEvent.addLocalMonitorForEvents(matching: .flagsChanged, handler: { event in
if event.modifierFlags.contains(.shift) {
print("按下shift健")
// print("按下shift健")
self.shiftKeyPressed = true
}else {
print("松开shift健")
// print("松开shift健")
self.shiftKeyPressed = false
}
return event
Expand Down
15 changes: 15 additions & 0 deletions OSXChatGPT/OSXChatGPT/DataProvider/Localization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ enum Localization {
case ShareOrNot
case AnswerStream
case AnswerOneTime
case Setting
case HideDynamicBackground
case DisplayDynamicBackground
case Displayed
case Hidden

var localized: String {
switch self {
Expand Down Expand Up @@ -169,6 +174,16 @@ enum Localization {
return String(format: NSLocalizedString("AnswerStream", comment: ""))
case .AnswerOneTime:
return String(format: NSLocalizedString("AnswerOneTime", comment: ""))
case .Setting:
return String(format: NSLocalizedString("Setting", comment: ""))
case .HideDynamicBackground:
return String(format: NSLocalizedString("HideDynamicBackground", comment: ""))
case .DisplayDynamicBackground:
return String(format: NSLocalizedString("DisplayDynamicBackground", comment: ""))
case .Displayed:
return String(format: NSLocalizedString("Displayed", comment: ""))
case .Hidden:
return String(format: NSLocalizedString("Hidden", comment: ""))
}

}
Expand Down
10 changes: 5 additions & 5 deletions OSXChatGPT/OSXChatGPT/DataProvider/ServerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ class ServerManager {
let da = NSData(base64Encoded: getDataBase64, options: NSData.Base64DecodingOptions.init(rawValue: 0)),
let dataString = String(data: da as Data, encoding: .utf8) {
self.getDataToken = dataString
print("获取getDataToken成功")
// print("获取getDataToken成功")
}else {
print("获取getDataToken失败")
// print("获取getDataToken失败")
}
if let uploadDataBase64 = json["uploadData"] as? String,
let da = NSData(base64Encoded: uploadDataBase64, options: NSData.Base64DecodingOptions.init(rawValue: 0)),
let dataString = String(data: da as Data, encoding: .utf8) {
self.uploadDataToken = dataString
print("获取uploadDataToken成功")
// print("获取uploadDataToken成功")
}else {
print("获取uploadDataToken失败")
// print("获取uploadDataToken失败")
}
self.loading = false
if self.uploadDataToken.isEmpty || self.getDataToken.isEmpty {
Expand All @@ -54,7 +54,7 @@ class ServerManager {
}
}
}else {
print("获取Token失败")
// print("获取Token失败")
self.loading = false
DispatchQueue.global().asyncAfter(deadline: .now() + 3) {
self.checkToken()
Expand Down
4 changes: 2 additions & 2 deletions OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -312,13 +312,13 @@ extension ViewModel {
self.showStopAnswerBtn = true
}

var stream: String = ""
// var stream: String = ""
ChatGPTManager.shared.askChatGPTStream(messages: messages, prompt: prompt, chatGpt: currentConversation?.chatGPT) { rsp in
if rsp.request.answerType == .stream {
isFeedback = true
//流式请求
if rsp.state == .replyStart {
stream = ""
// stream = ""
DispatchQueue.main.async {
self.removeGptThinkMessage()
newMsg = Message(context: CoreDataManager.shared.container.viewContext)
Expand Down
7 changes: 4 additions & 3 deletions OSXChatGPT/OSXChatGPT/Interface/OSXChatGPTApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ struct OSXChatGPTApp: App {
.commands { SidebarCommands() }
.commands { CommandGroup(replacing: CommandGroupPlacement.newItem) {} }
.commands {
CommandMenu("Setting") {
Menu(viewModel.showDynamicBackground ? "隐藏动态背景" : "显示动态背景") {
Text(viewModel.showDynamicBackground ? "已显示" : "已隐藏")
CommandMenu(Localization.Setting.localized) {
Menu(viewModel.showDynamicBackground ? Localization.HideDynamicBackground.localized : Localization.DisplayDynamicBackground.localized) {
Text(viewModel.showDynamicBackground ? Localization.Displayed.localized : Localization.Hidden.localized)
} primaryAction: {
viewModel.showDynamicBackground.toggle()
ProjectSettingManager.shared.showDynamicBackground = viewModel.showDynamicBackground
viewModel.showDynamicBackground = viewModel.showDynamicBackground
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions OSXChatGPT/OSXChatGPT/WindowView/AIPromptInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ struct AIPromptInputView: View {
.padding(.leading, 20)
.padding(.bottom, 0)
.frame(height: 18)
// Text("(选填)")
// .font(Font.system(size: 11))
// .padding(.top, 5)
// .foregroundColor(.gray.opacity(0.6))
// .frame(height: 18)
Text(Localization.ShareYourPromptToLibrary.localized)
.font(Font.system(size: 10))
.padding(.top, 5)
Expand Down Expand Up @@ -133,7 +128,7 @@ struct AIPromptInputView: View {

Button {
if title.isEmpty || content.isEmpty {
self.isPresented = false

return
}
viewModel.addPrompt(title: title, content: content, author: author, isToggleOn: isToggleOn)
Expand Down
107 changes: 61 additions & 46 deletions OSXChatGPT/OSXChatGPT/WindowView/AIPromptPopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,59 +84,74 @@ struct AIPromptPopCellView: View {
let item: Prompt
let isSelected: Bool
var body: some View {
HStack {
if self.isSelected {
Image(systemName: "checkmark.square.fill")
.resizable()
.scaledToFit()
.frame(width: 20, height: 20)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.background(Color.blue)
.clipShape(Circle())
.padding(5)
ZStack {
HStack {
if self.isSelected {
Image(systemName: "checkmark.square.fill")
.resizable()
.scaledToFit()
.frame(width: 20, height: 20)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.background(Color.blue)
.clipShape(Circle())
.padding(5)

} else {
Circle()
.stroke(Color.blue, lineWidth: 1)
.frame(width: 20, height: 20)
.padding(5)
}
if item.promptType == .hint {
VStack(alignment: .leading, spacing: 4) {
HStack {
Text(Localization.DefaultNoPrompt.localized)
.font(Font.system(size: 15))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.trailing, 6)
.padding(.bottom, 6)
Text(Localization.CurrentSelectPrompt.localized)
.font(Font.system(size: 14))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.bottom, 6)
Spacer()
Text(Localization.NoPromptToLibraryAdd.localized)
.font(Font.system(size: 11))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.bottom, 6)
}
Text(Localization.SelectOnlyOnePromptPerSession.localized)
.font(.subheadline)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.6) : .white)
}.padding(.leading, 2)
}else {
VStack(alignment: .leading, spacing: 4) {
Text(item.title ?? "")
.font(.headline)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.foregroundColor(.primary)
.padding(.bottom, 5)
Text(item.prompt ?? "")
.font(.subheadline)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.6) : .white.opacity(0.9))
}.padding(.leading, 2)
}

Spacer()

} else {
Circle()
.stroke(Color.blue, lineWidth: 1)
.frame(width: 20, height: 20)
.padding(5)
}
if item.promptType == .hint {
VStack(alignment: .leading, spacing: 4) {
if let author = item.author, !author.isEmpty {
VStack {
HStack {
Text(Localization.DefaultNoPrompt.localized)
.font(Font.system(size: 15))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.trailing, 6)
.padding(.bottom, 6)
Text(Localization.CurrentSelectPrompt.localized)
.font(Font.system(size: 14))
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.bottom, 6)
Spacer()
Text(Localization.NoPromptToLibraryAdd.localized)
.font(Font.system(size: 11))
Text("@\(author)")
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.padding(.bottom, 6)
.font(.system(size: 11))
.padding(.top, 5)
}
Text(Localization.SelectOnlyOnePromptPerSession.localized)
.font(.subheadline)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.6) : .white)
}.padding(.leading, 2)
}else {
VStack(alignment: .leading, spacing: 4) {
Text(item.title ?? "")
.font(.headline)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.foregroundColor(.primary)
.padding(.bottom, 6)
Text(item.prompt ?? "")
.font(.subheadline)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.6) : .white)
}.padding(.leading, 2)
Spacer()
}
}

Spacer()
}
.frame(height: 60)
.padding(.vertical, 5)
Expand Down
5 changes: 3 additions & 2 deletions OSXChatGPT/OSXChatGPT/WindowView/AIPromptView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ struct AIPromptView: View {
.background(Color.clear)
.padding(.leading, 16)
.padding(.trailing, 16)
.padding(.bottom, 16)
}
.frame(width: geometry.size.width, height: geometry.size.height)

Expand Down Expand Up @@ -239,11 +240,11 @@ struct AIPromptCellView: View {

}

if let author = item.author {
if let author = item.author, !author.isEmpty {
VStack {
HStack {
Spacer()
Text("\(author)")
Text("@\(author)")
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.8) : .white)
.font(.system(size: 11))
.padding(.top, 5)
Expand Down
1 change: 0 additions & 1 deletion OSXChatGPT/OSXChatGPT/WindowView/ChatRoomToolBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ struct TemperatureSliderView: View {
.padding(.top, 10)
.padding(.bottom, 10)
.onChange(of: progress) { newValue in
print("aaaa\(newValue)")
let formattedValue = String(format: "%.1f", newValue * 2)
change = formattedValue

Expand Down
10 changes: 8 additions & 2 deletions OSXChatGPT/OSXChatGPT/WindowView/ChatRoomView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct ChatRoomView: View {


.onAppear {
print("View appeared!")
// print("View appeared!")
newMessageText = conversation?.lastInputText ?? ""
KeyboardMonitor.shared.startMonitorPasteboard()
KeyboardMonitor.shared.startMonitorShiftKey()
Expand All @@ -103,7 +103,7 @@ struct ChatRoomView: View {
ServerManager.shared.checkToken()//获取最新teton
}
.onDisappear {
print("View disappeared!")
// print("View disappeared!")
self.isOnAppear = false
conversation?.lastInputText = newMessageText

Expand Down Expand Up @@ -159,6 +159,12 @@ struct ChatRoomCellView: View {
}) {
Text(Localization.deleteMessage.localized)
}
Button(action: {
NSPasteboard.general.prepareForNewContents()
NSPasteboard.general.setString(message.text ?? "", forType: .string)
}) {
Text(Localization.copyMessage.localized)
}
}

// VStack {
Expand Down
8 changes: 3 additions & 5 deletions OSXChatGPT/OSXChatGPT/WindowView/SessionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ struct ChatRowView: View {
.font(.headline)
.foregroundColor(NSColor(r: 224, g: 87, b: 114).toColor())
}else {
if chat.prompt?.title != nil {
if chat.prompt?.title != nil && !chat.prompt!.title!.isEmpty {
Text(chat.prompt?.title ?? "")
.font(.headline)
}else if chat.remark != nil {
}else if chat.remark != nil && !chat.remark!.isEmpty {
Text(chat.remark ?? "")
.font(.headline)
}else if chat.lastMessage?.text != nil {
Expand Down Expand Up @@ -211,7 +211,6 @@ struct ChatRowContentNSView: NSViewRepresentable {

@objc func handleRightClick(_ sender: NSClickGestureRecognizer) {
if sender.state == .ended {
print("右键鼠标")
let menu = NSMenu(title: "")
menu.delegate = self
let editMenuItem = NSMenuItem(title: Localization.editRemark.localized, action: #selector(edit), keyEquivalent: "")
Expand All @@ -227,14 +226,13 @@ struct ChatRowContentNSView: NSViewRepresentable {

@MainActor @objc func handleLeftClick(_ sender: NSClickGestureRecognizer) {
if sender.state == .ended {
print("左边键鼠标")
parent.viewModel.currentConversation = parent.chat;
parent.viewModel.showUserInitialize = false
}
}

func menuDidClose(_ menu: NSMenu) {
print("menu menuDidClose!")

}

@MainActor @objc func edit() {
Expand Down
Loading

0 comments on commit cd245fc

Please sign in to comment.