-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(desktop): align transcription language options #7209
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,62 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| import XCTest | ||||||||||||||||||||||||||||||||||||||||||||||
| @testable import Omi_Computer | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| @MainActor | ||||||||||||||||||||||||||||||||||||||||||||||
| final class AssistantSettingsLanguageTests: XCTestCase { | ||||||||||||||||||||||||||||||||||||||||||||||
| private let languageKey = "transcriptionLanguage" | ||||||||||||||||||||||||||||||||||||||||||||||
| private let autoDetectKey = "transcriptionAutoDetect" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| override func setUp() { | ||||||||||||||||||||||||||||||||||||||||||||||
| super.setUp() | ||||||||||||||||||||||||||||||||||||||||||||||
| UserDefaults.standard.removeObject(forKey: languageKey) | ||||||||||||||||||||||||||||||||||||||||||||||
| UserDefaults.standard.removeObject(forKey: autoDetectKey) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| override func tearDown() { | ||||||||||||||||||||||||||||||||||||||||||||||
| UserDefaults.standard.removeObject(forKey: languageKey) | ||||||||||||||||||||||||||||||||||||||||||||||
| UserDefaults.standard.removeObject(forKey: autoDetectKey) | ||||||||||||||||||||||||||||||||||||||||||||||
| super.tearDown() | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+9
to
+19
Contributor
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func testNormalizesChineseAliasesToDeepgramCode() { | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("chinese"), "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("zh"), "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("zh_Hans"), "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("中文"), "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("zh-Hant"), "zh-TW") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("粤语"), "zh-HK") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func testPersistedAliasIsNormalizedAndWrittenBackOnRead() { | ||||||||||||||||||||||||||||||||||||||||||||||
| UserDefaults.standard.set("chinese", forKey: languageKey) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.shared.transcriptionLanguage, "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(UserDefaults.standard.string(forKey: languageKey), "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func testChineseDoesNotUseAutoDetectMultiLanguageMode() { | ||||||||||||||||||||||||||||||||||||||||||||||
| AssistantSettings.shared.transcriptionLanguage = "chinese" | ||||||||||||||||||||||||||||||||||||||||||||||
| AssistantSettings.shared.transcriptionAutoDetect = true | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.shared.effectiveTranscriptionLanguage, "zh-CN") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertFalse(AssistantSettings.supportsAutoDetect("chinese")) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func testBrazilianPortugueseAliasIsSupported() { | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.normalizeTranscriptionLanguageCode("br"), "pt-BR") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(AssistantSettings.shared.transcriptionLanguage, "en") | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(AssistantSettings.supportsAutoDetect("br")) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| func testDesktopLanguagePickerIncludesBackendSupportedLanguages() { | ||||||||||||||||||||||||||||||||||||||||||||||
| let languageCodes = Set(AssistantSettings.supportedLanguages.map(\.code)) | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("zh-CN")) | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("zh-HK")) | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("zh-TW")) | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("ar")) | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("bn")) | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("ta")) | ||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue(languageCodes.contains("ur")) | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
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.
transcriptionLanguagegetter silently writes a normalized value back toUserDefaultswithout postingtranscriptionSettingsDidChange. Every other mutation totranscriptionLanguagegoes through the setter, which always posts the notification so observers (e.g., the audio stack) can react. If an observer is active at the moment this one-time migration fires, it won't be told the value changed, leaving the streamed language code potentially stale until the next explicit set.