Skip to content

Commit

Permalink
Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderLineChan committed Apr 23, 2023
1 parent bfd719a commit d03a6b2
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 70 deletions.
22 changes: 22 additions & 0 deletions OSXChatGPT/OSXChatGPT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
CB2F972029CE1ADC004EBD96 /* OSXChatGPT.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CBC4B0FD29B8BF9600650296 /* OSXChatGPT.xcdatamodeld */; };
CB2F972229CED6AE004EBD96 /* ChatRoomInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB2F972129CED6AE004EBD96 /* ChatRoomInputView.swift */; };
CB2F972829CEFB65004EBD96 /* ChatRoomToolBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB2F972729CEFB65004EBD96 /* ChatRoomToolBar.swift */; };
CB373A9B29F56CFF00B8D9BE /* Localization.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB373A9A29F56CFF00B8D9BE /* Localization.swift */; };
CB4D1FC429F195E60010D063 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = CB4D1FC629F195E60010D063 /* Localizable.strings */; };
CB53A3BE29D48C8F00A5B8FC /* Prompt+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB53A3BC29D48C8F00A5B8FC /* Prompt+CoreDataClass.swift */; };
CB53A3BF29D48C8F00A5B8FC /* Prompt+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB53A3BD29D48C8F00A5B8FC /* Prompt+CoreDataProperties.swift */; };
CBD5AB6429E6DE9A007B6625 /* ProjectSettingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBD5AB6329E6DE9A007B6625 /* ProjectSettingManager.swift */; };
Expand Down Expand Up @@ -138,6 +140,9 @@
CB2D438829F0183A007742AE /* ChatGPT+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChatGPT+CoreDataProperties.swift"; sourceTree = "<group>"; };
CB2F972129CED6AE004EBD96 /* ChatRoomInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomInputView.swift; sourceTree = "<group>"; };
CB2F972729CEFB65004EBD96 /* ChatRoomToolBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomToolBar.swift; sourceTree = "<group>"; };
CB373A9A29F56CFF00B8D9BE /* Localization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Localization.swift; sourceTree = "<group>"; };
CB4D1FC529F195E60010D063 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
CB4D1FC729F195EA0010D063 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
CB53A3BC29D48C8F00A5B8FC /* Prompt+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Prompt+CoreDataClass.swift"; sourceTree = "<group>"; };
CB53A3BD29D48C8F00A5B8FC /* Prompt+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Prompt+CoreDataProperties.swift"; sourceTree = "<group>"; };
CBC4B0FE29B8BF9600650296 /* OSXChatGPT.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = OSXChatGPT.xcdatamodel; sourceTree = "<group>"; };
Expand Down Expand Up @@ -214,6 +219,7 @@
182B437129BC5D1B00F06778 /* ChatGPTManager.swift */,
182B436F29BC5D1B00F06778 /* CoreDataManager.swift */,
182B437029BC5D1B00F06778 /* ViewModel.swift */,
CB373A9A29F56CFF00B8D9BE /* Localization.swift */,
CBD5AB6329E6DE9A007B6625 /* ProjectSettingManager.swift */,
CB28A52129C07BE500F0286A /* KeyboardMonitor.swift */,
CB27657229D30F1400897E0E /* AIPromptViewMdoel.swift */,
Expand Down Expand Up @@ -261,6 +267,7 @@
CBC4B11429B8CB1B00650296 /* Models */,
182B42B529BBA82800F06778 /* Storyboard.storyboard */,
CBC4B0FD29B8BF9600650296 /* OSXChatGPT.xcdatamodeld */,
CB4D1FC629F195E60010D063 /* Localizable.strings */,
CB1DCAC529B4F09F00B1D4E1 /* Assets.xcassets */,
CB1DCACA29B4F09F00B1D4E1 /* OSXChatGPT.entitlements */,
CB1DCAC729B4F09F00B1D4E1 /* Preview Content */,
Expand Down Expand Up @@ -418,6 +425,7 @@
knownRegions = (
en,
Base,
"zh-Hans",
);
mainGroup = CB1DCAB529B4F09D00B1D4E1;
packageReferences = (
Expand All @@ -440,6 +448,7 @@
buildActionMask = 2147483647;
files = (
CB1DCAC929B4F09F00B1D4E1 /* Preview Assets.xcassets in Resources */,
CB4D1FC429F195E60010D063 /* Localizable.strings in Resources */,
CB1DCAC629B4F09F00B1D4E1 /* Assets.xcassets in Resources */,
182B42B629BBA82800F06778 /* Storyboard.storyboard in Resources */,
);
Expand All @@ -454,6 +463,7 @@
files = (
CB1F012F29E999EF009CF942 /* Segment.swift in Sources */,
CB1F015C29EAFBF5009CF942 /* MessageText+CoreDataProperties.swift in Sources */,
CB373A9B29F56CFF00B8D9BE /* Localization.swift in Sources */,
CB1F015129E9BC8C009CF942 /* Tokenizer.swift in Sources */,
CB2449FA29D7FE38006EE829 /* ServerManager.swift in Sources */,
CB1F014829E99B5E009CF942 /* Int+IsOdd.swift in Sources */,
Expand Down Expand Up @@ -518,6 +528,18 @@
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
CB4D1FC629F195E60010D063 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
CB4D1FC529F195E60010D063 /* en */,
CB4D1FC729F195EA0010D063 /* zh-Hans */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
CB1DCACB29B4F09F00B1D4E1 /* Debug */ = {
isa = XCBuildConfiguration;
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 @@ -103,9 +103,9 @@ enum ChatGPTAnswerType: CaseIterable, ToolBarMenuProtocol {
var value: String {
switch self {
case .stream:
return "流式"
return Localization.AnswerStream.localized
case .oneTime:
return "单式"
return Localization.AnswerOneTime.localized
}
}
case stream
Expand Down
180 changes: 180 additions & 0 deletions OSXChatGPT/OSXChatGPT/DataProvider/Localization.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
//
// Localization.swift
// OSXChatGPT
//
// Created by CoderChan on 2023/4/23.
//

import Foundation
import SwiftUI


enum Localization {
case newChat
case prompt(_ text: String)
case editRemark
case deleteSession
case EditConversationRemark
case EnterRemark
case fasterResponse
case PromptLibrary
case NoLoginRequired
case NoMonthlyFee
case BetterApplication
case adMovie
case adWebsite
case UpdateAPIKey
case EnterAPIKey
case EnterYourAPIKey
case YouNeedApiKey
case GetYourAPIKey
case Cancel
case Save
case TheAppWillConnectOpenAIServer
case deleteMessage
case copyMessage
case ParameterAdjustment
case TemperatureT(_ text: String)
case ModelT(_ text: String)
case ContextT(_ text: String)
case Answer
case Prompts
case ClearMessage
case StopAnswer
case Empty
case CurrentTemperature
case RemoveShortcuts
case AddShortcuts
case DeleteData
case PleaseClickUpperRightAddCustomPrompt
case SelectPrompt
case Confirm
case Library
case DefaultNoPrompt
case CurrentSelectPrompt
case NoPromptToLibraryAdd
case SelectOnlyOnePromptPerSession
case CustomAdd
case Title
case Required
case Author
case ShareYourPromptToLibrary
case ShareOrNot
case AnswerStream
case AnswerOneTime

var localized: String {
switch self {
case .newChat:
return String(format: NSLocalizedString("newChat", comment: ""))
case .prompt(let t):
return String(format: NSLocalizedString("Prompt", comment: ""), t)
case .editRemark:
return String(format: NSLocalizedString("editRemark", comment: ""))
case .deleteSession:
return String(format: NSLocalizedString("deleteSession", comment: ""))
case .EditConversationRemark:
return String(format: NSLocalizedString("EditConversationRemark", comment: ""))
case .EnterRemark:
return String(format: NSLocalizedString("EnterRemark", comment: ""))
case .fasterResponse:
return String(format: NSLocalizedString("FasterResponse", comment: ""))
case .PromptLibrary:
return String(format: NSLocalizedString("PromptLibrary", comment: ""))
case .NoLoginRequired:
return String(format: NSLocalizedString("NoLoginRequired", comment: ""))
case .NoMonthlyFee:
return String(format: NSLocalizedString("NoMonthlyFee", comment: ""))
case .BetterApplication:
return String(format: NSLocalizedString("BetterApplication", comment: ""))
case .adMovie:
return String(format: NSLocalizedString("adMovie", comment: ""))
case .adWebsite:
return String(format: NSLocalizedString("adWebsite", comment: ""))
case .UpdateAPIKey:
return String(format: NSLocalizedString("UpdateAPIKey", comment: ""))
case .EnterAPIKey:
return String(format: NSLocalizedString("EnterAPIKey", comment: ""))
case .EnterYourAPIKey:
return String(format: NSLocalizedString("EnterYourAPIKey", comment: ""))
case .YouNeedApiKey:
return String(format: NSLocalizedString("YouNeedApiKey", comment: ""))
case .GetYourAPIKey:
return String(format: NSLocalizedString("GetYourAPIKey", comment: ""))
case .Cancel:
return String(format: NSLocalizedString("Cancel", comment: ""))
case .Save:
return String(format: NSLocalizedString("Save", comment: ""))
case .TheAppWillConnectOpenAIServer:
return String(format: NSLocalizedString("TheAppWillConnectOpenAIServer", comment: ""))
case .deleteMessage:
return String(format: NSLocalizedString("deleteMessage", comment: ""))
case .copyMessage:
return String(format: NSLocalizedString("copyMessage", comment: ""))
case .ParameterAdjustment:
return String(format: NSLocalizedString("ParameterAdjustment", comment: ""))
case .TemperatureT(let t):
return String(format: NSLocalizedString("TemperatureT", comment: ""), t)
case .ModelT(let t):
return String(format: NSLocalizedString("ModelT", comment: ""), t)
case .ContextT(let t):
return String(format: NSLocalizedString("ContextT", comment: ""), t)
case .Answer:
return String(format: NSLocalizedString("Answer", comment: ""))
case .Prompts:
return String(format: NSLocalizedString("Prompts", comment: ""))
case .ClearMessage:
return String(format: NSLocalizedString("ClearMessage", comment: ""))
case .StopAnswer:
return String(format: NSLocalizedString("StopAnswer", comment: ""))
case .Empty:
return String(format: NSLocalizedString("Empty", comment: ""))
case .CurrentTemperature:
return String(format: NSLocalizedString("CurrentTemperature", comment: ""))
case .RemoveShortcuts:
return String(format: NSLocalizedString("RemoveShortcuts", comment: ""))
case .AddShortcuts:
return String(format: NSLocalizedString("AddShortcuts", comment: ""))
case .DeleteData:
return String(format: NSLocalizedString("DeleteData", comment: ""))
case .PleaseClickUpperRightAddCustomPrompt:
return String(format: NSLocalizedString("PleaseClickUpperRightAddCustomPrompt", comment: ""))
case .SelectPrompt:
return String(format: NSLocalizedString("SelectPrompt", comment: ""))
case .Confirm:
return String(format: NSLocalizedString("Confirm", comment: ""))
case .Library:
return String(format: NSLocalizedString("Library", comment: ""))
case .DefaultNoPrompt:
return String(format: NSLocalizedString("DefaultNoPrompt", comment: ""))
case .CurrentSelectPrompt:
return String(format: NSLocalizedString("CurrentSelectPrompt", comment: ""))
case .NoPromptToLibraryAdd:
return String(format: NSLocalizedString("NoPromptToLibraryAdd", comment: ""))
case .SelectOnlyOnePromptPerSession:
return String(format: NSLocalizedString("SelectOnlyOnePromptPerSession", comment: ""))
case .CustomAdd:
return String(format: NSLocalizedString("CustomAdd", comment: ""))
case .Title:
return String(format: NSLocalizedString("Title", comment: ""))
case .Required:
return String(format: NSLocalizedString("Required", comment: ""))
case .Author:
return String(format: NSLocalizedString("Author", comment: ""))
case .ShareYourPromptToLibrary:
return String(format: NSLocalizedString("ShareYourPromptToLibrary", comment: ""))
case .ShareOrNot:
return String(format: NSLocalizedString("ShareOrNot", comment: ""))
case .AnswerStream:
return String(format: NSLocalizedString("AnswerStream", comment: ""))
case .AnswerOneTime:
return String(format: NSLocalizedString("AnswerOneTime", comment: ""))
}

}

}




4 changes: 2 additions & 2 deletions OSXChatGPT/OSXChatGPT/DataProvider/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ extension ViewModel {
if ChatGPTManager.shared.answerType.valueBool {
self.showStopAnswerBtn = true
}

var stream: String = ""
ChatGPTManager.shared.askChatGPTStream(messages: messages, prompt: prompt, chatGpt: currentConversation?.chatGPT) { rsp in
if rsp.request.answerType == .stream {
Expand Down Expand Up @@ -417,9 +418,8 @@ extension ViewModel {
self.messages.append(newMsg!)
}
}
newMsg?.text = rsp.text
//失败
CoreDataManager.shared.saveData()
//失败
newMsg?.text = rsp.text
if self.currentConversation?.sesstionId == sesstionId {
if self.messages.count > 0 {
Expand Down
20 changes: 10 additions & 10 deletions OSXChatGPT/OSXChatGPT/WindowView/AIPromptInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct AIPromptInputView: View {
VStack {
VStack {
Spacer()
Text("自定义添加")
Text(Localization.CustomAdd.localized)
.font(.title3)
.foregroundColor((colorScheme == .dark) ? .white.opacity(0.9) :.black.opacity(0.9))
Spacer()
Expand All @@ -32,13 +32,13 @@ struct AIPromptInputView: View {

VStack {
HStack {
Text("标题")
Text(Localization.Title.localized)
.font(.title3)
.padding(.top, 5)
.padding(.leading, 20)
.padding(.bottom, 0)
.frame(height: 18)
Text("*必填")
Text(Localization.Required.localized)
.font(Font.system(size: 11))
.padding(.top, 5)
.foregroundColor(.gray.opacity(0.6))
Expand All @@ -58,13 +58,13 @@ struct AIPromptInputView: View {
.padding(.trailing, 20)

HStack {
Text("修饰语")
Text(Localization.Prompts.localized)
.font(.title3)
.padding(.top, 5)
.padding(.leading, 20)
.padding(.bottom, 0)
.frame(height: 18)
Text("*必填")
Text(Localization.Required.localized)
.font(Font.system(size: 11))
.padding(.top, 5)
.foregroundColor(.gray.opacity(0.6))
Expand All @@ -84,7 +84,7 @@ struct AIPromptInputView: View {
.padding(.trailing, 20)

HStack {
Text("作者")
Text(Localization.Author.localized)
.font(.title3)
.padding(.top, 5)
.padding(.leading, 20)
Expand All @@ -95,7 +95,7 @@ struct AIPromptInputView: View {
// .padding(.top, 5)
// .foregroundColor(.gray.opacity(0.6))
// .frame(height: 18)
Text("分享您的修饰语到词库")
Text(Localization.ShareYourPromptToLibrary.localized)
.font(Font.system(size: 10))
.padding(.top, 5)
.foregroundColor(.gray.opacity(0.6))
Expand All @@ -119,7 +119,7 @@ struct AIPromptInputView: View {

VStack {
HStack {
Toggle("是否分享", isOn: $isToggleOn)
Toggle(Localization.ShareOrNot.localized, isOn: $isToggleOn)
.padding()
.foregroundColor(.gray)
.font(Font.system(size: 13))
Expand All @@ -128,7 +128,7 @@ struct AIPromptInputView: View {
Button {
self.isPresented = false
} label: {
Text("取消")
Text(Localization.Cancel.localized)
}

Button {
Expand All @@ -140,7 +140,7 @@ struct AIPromptInputView: View {
self.isPresented = false

} label: {
Text("确定")
Text(Localization.Confirm.localized)

}
.padding(.trailing, 20)
Expand Down
Loading

0 comments on commit d03a6b2

Please sign in to comment.