add effective language resolution for general.language support
This commit is contained in:
@@ -1983,3 +1983,59 @@ func TestConfig_ToTranscriberConfig_Threads(t *testing.T) {
|
||||
t.Errorf("Threads = %d, want 4", transcriberConfig.Threads)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfig_EffectiveLanguage(t *testing.T) {
|
||||
t.Run("only general.language set", func(t *testing.T) {
|
||||
config := &Config{
|
||||
General: GeneralConfig{
|
||||
Language: "es",
|
||||
},
|
||||
Transcription: TranscriptionConfig{
|
||||
Provider: "openai",
|
||||
Model: "whisper-1",
|
||||
Language: "", // not set
|
||||
},
|
||||
}
|
||||
|
||||
transcriberConfig := config.ToTranscriberConfig()
|
||||
if transcriberConfig.Language != "es" {
|
||||
t.Errorf("Language = %q, want %q", transcriberConfig.Language, "es")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("transcription.language overrides general.language", func(t *testing.T) {
|
||||
config := &Config{
|
||||
General: GeneralConfig{
|
||||
Language: "es",
|
||||
},
|
||||
Transcription: TranscriptionConfig{
|
||||
Provider: "openai",
|
||||
Model: "whisper-1",
|
||||
Language: "en", // overrides general
|
||||
},
|
||||
}
|
||||
|
||||
transcriberConfig := config.ToTranscriberConfig()
|
||||
if transcriberConfig.Language != "en" {
|
||||
t.Errorf("Language = %q, want %q", transcriberConfig.Language, "en")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("neither set results in auto", func(t *testing.T) {
|
||||
config := &Config{
|
||||
General: GeneralConfig{
|
||||
Language: "",
|
||||
},
|
||||
Transcription: TranscriptionConfig{
|
||||
Provider: "openai",
|
||||
Model: "whisper-1",
|
||||
Language: "",
|
||||
},
|
||||
}
|
||||
|
||||
transcriberConfig := config.ToTranscriberConfig()
|
||||
if transcriberConfig.Language != "" {
|
||||
t.Errorf("Language = %q, want empty (auto)", transcriberConfig.Language)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func (c *Config) ToRecordingConfig() recording.Config {
|
||||
func (c *Config) ToTranscriberConfig() transcriber.Config {
|
||||
config := transcriber.Config{
|
||||
Provider: c.Transcription.Provider,
|
||||
Language: c.Transcription.Language,
|
||||
Language: c.resolveEffectiveLanguage(),
|
||||
Model: c.Transcription.Model,
|
||||
Keywords: c.Keywords,
|
||||
Threads: c.Transcription.Threads,
|
||||
@@ -34,6 +34,15 @@ func (c *Config) ToTranscriberConfig() transcriber.Config {
|
||||
return config
|
||||
}
|
||||
|
||||
// resolveEffectiveLanguage returns the effective language for transcription.
|
||||
// transcription.language overrides general.language if set.
|
||||
func (c *Config) resolveEffectiveLanguage() string {
|
||||
if c.Transcription.Language != "" {
|
||||
return c.Transcription.Language
|
||||
}
|
||||
return c.General.Language
|
||||
}
|
||||
|
||||
// resolveAPIKeyForProvider returns the API key for a provider from multiple sources
|
||||
func (c *Config) resolveAPIKeyForProvider(provider string) string {
|
||||
providerName := provider
|
||||
|
||||
@@ -512,4 +512,12 @@ Started: Sun Feb 1 12:22:47 AM CET 2026
|
||||
- Added `General GeneralConfig` field to Config struct with toml tag 'general'
|
||||
- Language field has ISO 639-1 code comment, empty for auto-detect
|
||||
- TranscriptionConfig.Language kept for backwards compat (will be used as override)
|
||||
- All tests passing, typecheck passes
|
||||
|
||||
### Task 48: Update config loading to handle general language
|
||||
- Added `resolveEffectiveLanguage()` method to Config in convert.go
|
||||
- Logic: transcription.language overrides general.language if set
|
||||
- Updated `ToTranscriberConfig()` to use `resolveEffectiveLanguage()`
|
||||
- Note: TOML loading already works automatically via struct tags (no load.go changes needed)
|
||||
- Added 3 tests in config_test.go: only general set, transcription overrides general, neither set (auto)
|
||||
- All tests passing, typecheck passes
|
||||
+1
-1
@@ -31,7 +31,7 @@
|
||||
"Config with neither set results in effective language '' (auto)",
|
||||
"Typecheck passes"
|
||||
],
|
||||
"passes": false
|
||||
"passes": true
|
||||
},
|
||||
{
|
||||
"title": "Update config template to include general section",
|
||||
|
||||
Reference in New Issue
Block a user