-
Notifications
You must be signed in to change notification settings - Fork 105
Fix Chinese input and Apple ASR locale selection #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import Foundation | ||
|
|
||
| enum SpeechLocaleResolver { | ||
| static var prefersChineseRecognition: Bool { | ||
| Locale.preferredLanguages.contains { Self.languageCode(from: $0) == "zh" } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| static func preferredRecognitionLocale() -> Locale { | ||
| let selectedModel = SettingsStore.shared.selectedSpeechModel | ||
| switch selectedModel { | ||
| case .appleSpeech, .appleSpeechAnalyzer, .cohereTranscribeSixBit: | ||
| return Self.locale(for: SettingsStore.shared.selectedCohereLanguage) | ||
| default: | ||
| break | ||
| } | ||
|
|
||
| if let preferredChinese = Locale.preferredLanguages.first(where: { Self.languageCode(from: $0) == "zh" }) { | ||
| return Locale(identifier: preferredChinese) | ||
| } | ||
| return Locale.autoupdatingCurrent | ||
| } | ||
|
|
||
| private static func locale(for language: SettingsStore.CohereLanguage) -> Locale { | ||
| switch language { | ||
| case .arabic: | ||
| return Locale(identifier: "ar-SA") | ||
| case .german: | ||
| return Locale(identifier: "de-DE") | ||
| case .greek: | ||
| return Locale(identifier: "el-GR") | ||
| case .english: | ||
| return Locale(identifier: "en-US") | ||
| case .spanish: | ||
| return Locale(identifier: "es-ES") | ||
| case .french: | ||
| return Locale(identifier: "fr-FR") | ||
| case .italian: | ||
| return Locale(identifier: "it-IT") | ||
| case .japanese: | ||
| return Locale(identifier: "ja-JP") | ||
| case .korean: | ||
| return Locale(identifier: "ko-KR") | ||
| case .dutch: | ||
| return Locale(identifier: "nl-NL") | ||
| case .polish: | ||
| return Locale(identifier: "pl-PL") | ||
| case .portuguese: | ||
| return Locale(identifier: "pt-BR") | ||
| case .vietnamese: | ||
| return Locale(identifier: "vi-VN") | ||
| case .simplifiedChinese: | ||
| return Locale(identifier: "zh-CN") | ||
| case .traditionalChinese: | ||
| return Locale(identifier: "zh-TW") | ||
| } | ||
| } | ||
|
|
||
| private static func languageCode(from identifier: String) -> String? { | ||
| let normalized = identifier.lowercased() | ||
| let separator = normalized.firstIndex(where: { $0 == "-" || $0 == "_" }) ?? normalized.endIndex | ||
| let code = String(normalized[..<separator]) | ||
| return code.isEmpty ? nil : code | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
zhsetting without forcing zh-TWThe migration path for older installs maps stored
SelectedCohereLanguage == "zh"directly to.traditionalChinese. BecauseSpeechLocaleResolver.locale(for:)maps that tozh-TW, existing users who previously chose generic Mandarin are now forced onto the Taiwan locale when using Apple speech models, which can degrade recognition for users expecting mainland/Simplified behavior. The migration should preserve neutrality (or infer from system Chinese locale) instead of hard-coding Traditional Chinese.Useful? React with 👍 / 👎.