implement editLanguage function in TUI with model compatibility warning

This commit is contained in:
leonardotrapani
2026-02-01 13:21:10 +01:00
parent e005184303
commit cc8c0c8a11
3 changed files with 86 additions and 2 deletions
+75 -1
View File
@@ -1,11 +1,85 @@
package tui
import (
"fmt"
"github.com/charmbracelet/huh"
"github.com/leonardotrapani/hyprvoice/internal/config"
"github.com/leonardotrapani/hyprvoice/internal/language"
"github.com/leonardotrapani/hyprvoice/internal/provider"
)
// editLanguage allows the user to select the global transcription language
func editLanguage(cfg *config.Config) error {
// implementation in task 5
// no model-specific warnings for global language selection
languageOptions := getLanguageOptions(nil)
selectedLanguage := cfg.General.Language
form := huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Title("Language").
Description("Select language for transcription (applies globally)").
Options(languageOptions...).
Filtering(true).
Value(&selectedLanguage),
),
).WithTheme(getTheme())
if err := form.Run(); err != nil {
return err
}
// check if current transcription model supports the selected language
if selectedLanguage != "" && cfg.Transcription.Provider != "" && cfg.Transcription.Model != "" {
registryName := mapConfigProviderToRegistry(cfg.Transcription.Provider)
model, err := provider.GetModel(registryName, cfg.Transcription.Model)
if err == nil && !model.SupportsLanguage(selectedLanguage) {
langName := language.FromCode(selectedLanguage).Name
if langName == "" {
langName = selectedLanguage
}
fmt.Println()
fmt.Println(StyleWarning.Render("Language-Model Compatibility Warning"))
fmt.Printf("Your current model '%s' does not support %s.\n", model.Name, langName)
fmt.Println()
fmt.Println(StyleMuted.Render("You can:"))
fmt.Println(StyleMuted.Render(" - Keep this language and change the model later"))
fmt.Println(StyleMuted.Render(" - Use 'Auto-detect' for language"))
fmt.Println(StyleMuted.Render(" - Choose a different language"))
fmt.Println()
var action string
actionForm := huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().
Title("What would you like to do?").
Options(
huh.NewOption("Keep this language (change model later)", "keep"),
huh.NewOption("Use Auto-detect instead", "auto"),
huh.NewOption("Choose a different language", "retry"),
).
Value(&action),
),
).WithTheme(getTheme())
if err := actionForm.Run(); err != nil {
return err
}
switch action {
case "auto":
selectedLanguage = ""
case "retry":
return editLanguage(cfg)
case "keep":
// proceed with incompatible language
}
}
}
cfg.General.Language = selectedLanguage
return nil
}
+10
View File
@@ -536,4 +536,14 @@ Started: Sun Feb 1 12:22:47 AM CET 2026
- Shows "Language (Auto-detect)" when empty, "Language ({name})" when set
- Added case SectionLanguage in runEditExisting switch calling editLanguage()
- Created stub configure_language.go with editLanguage() function (implementation in Task 5)
- All tests passing, typecheck passes
### Task 5: Create editLanguage function in TUI
- Implemented `editLanguage(cfg *config.Config)` in configure_language.go
- Uses `getLanguageOptions(nil)` for 58 options (57 languages + Auto-detect)
- huh.NewSelect with `.Filtering(true)` for searchable language picker
- Saves selected language to `cfg.General.Language`
- Checks if current transcription model supports selected language via `provider.GetModel()` + `model.SupportsLanguage()`
- Shows warning dialog with 3 options: keep incompatible language, use auto-detect, or choose different language
- Recursive retry flow if user chooses "Choose a different language"
- All tests passing, typecheck passes
+1 -1
View File
@@ -81,7 +81,7 @@
"Warning shown if current model doesn't support selected language",
"Typecheck passes"
],
"passes": false
"passes": true
},
{
"title": "Remove language from transcription edit flow",