Skip to content

Commit 423a0e7

Browse files
committed
feat: add language configuration for commit messages
- Add language field to config schema (en/es) - Implement GetLanguage() and SetLanguage() functions - Modify prompt generation to append language instruction - Add interactive language selection in config command - Display language in config get output Users can now configure commit message language via: - Manual config: language: es/en in .lazycommit.yaml - Interactive: lazycommit config set
1 parent c32a389 commit 423a0e7

3 files changed

Lines changed: 74 additions & 3 deletions

File tree

cmd/config.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ var getCmd = &cobra.Command{
3232
fmt.Println("Error getting endpoint:", err)
3333
os.Exit(1)
3434
}
35+
language := config.GetLanguage()
3536
fmt.Printf("Active Provider: %s\n", provider)
3637
fmt.Printf("Model: %s\n", model)
3738
fmt.Printf("Endpoint: %s\n", endpoint)
39+
fmt.Printf("Language: %s\n", language)
3840
},
3941
}
4042

@@ -99,6 +101,40 @@ func runInteractiveConfig() {
99101
currentModel = ""
100102
}
101103

104+
// Language configuration
105+
currentLanguage := config.GetLanguage()
106+
languagePrompt := &survey.Select{
107+
Message: "Choose a language for commit messages:",
108+
Options: []string{"English (en)", "Español (es)"},
109+
Default: func() string {
110+
if currentLanguage == "es" {
111+
return "Español (es)"
112+
}
113+
return "English (en)"
114+
}(),
115+
}
116+
var selectedLanguage string
117+
err = survey.AskOne(languagePrompt, &selectedLanguage)
118+
if err != nil {
119+
fmt.Println(err.Error())
120+
return
121+
}
122+
123+
// Extract language code from selection
124+
langCode := "en"
125+
if selectedLanguage == "Español (es)" {
126+
langCode = "es"
127+
}
128+
129+
if langCode != currentLanguage {
130+
err := config.SetLanguage(langCode)
131+
if err != nil {
132+
fmt.Printf("Error setting language: %v\n", err)
133+
return
134+
}
135+
fmt.Printf("Language set to: %s\n", langCode)
136+
}
137+
102138
// API key configuration - skip for copilot and anthropic
103139
if selectedProvider != "copilot" && selectedProvider != "anthropic" {
104140
apiKeyPrompt := &survey.Input{

internal/config/config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ProviderConfig struct {
2323
type Config struct {
2424
Providers map[string]ProviderConfig `mapstructure:"providers"`
2525
ActiveProvider string `mapstructure:"active_provider"`
26+
Language string `mapstructure:"language"`
2627
}
2728

2829
var cfg *Config
@@ -46,6 +47,9 @@ func InitConfig() {
4647
viper.SetDefault("providers.anthropic.model", "claude-haiku-4-5")
4748
viper.SetDefault("providers.anthropic.num_suggestions", 10)
4849

50+
// Set default language
51+
viper.SetDefault("language", "en")
52+
4953
viper.AutomaticEnv()
5054

5155
if err := viper.ReadInConfig(); err != nil {
@@ -286,6 +290,25 @@ func SetNumSuggestions(provider, numSuggestions string) error {
286290
return viper.WriteConfig()
287291
}
288292

293+
func GetLanguage() string {
294+
if cfg == nil {
295+
InitConfig()
296+
}
297+
if cfg.Language == "" {
298+
return "en" // Default to English
299+
}
300+
return cfg.Language
301+
}
302+
303+
func SetLanguage(language string) error {
304+
if cfg == nil {
305+
InitConfig()
306+
}
307+
cfg.Language = language
308+
viper.Set("language", language)
309+
return viper.WriteConfig()
310+
}
311+
289312
func getConfigDir() string {
290313
if xdgConfig := os.Getenv("XDG_CONFIG_HOME"); xdgConfig != "" {
291314
return xdgConfig

internal/config/prompts.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,21 @@ func GetSystemMessageFromConfig() string {
100100
// GetCommitMessagePromptFromConfig returns the commit message prompt from configuration
101101
func GetCommitMessagePromptFromConfig(diff string) string {
102102
config := GetPromptConfig()
103+
var basePrompt string
103104
if config.CommitMessageTemplate != "" {
104-
return fmt.Sprintf(config.CommitMessageTemplate, diff)
105+
basePrompt = fmt.Sprintf(config.CommitMessageTemplate, diff)
106+
} else {
107+
// Fallback to hardcoded default
108+
basePrompt = fmt.Sprintf("Based on the following git diff, generate 10 conventional commit messages. Each message should be on a new line, without any numbering or bullet points:\n\n%s", diff)
105109
}
106-
// Fallback to hardcoded default
107-
return fmt.Sprintf("Based on the following git diff, generate 10 conventional commit messages. Each message should be on a new line, without any numbering or bullet points:\n\n%s", diff)
110+
111+
// Add language instruction based on configuration
112+
language := GetLanguage()
113+
if language == "es" {
114+
basePrompt += "\n\nIMPORTANT: Generate all commit messages in Spanish."
115+
} else if language == "en" {
116+
basePrompt += "\n\nIMPORTANT: Generate all commit messages in English."
117+
}
118+
119+
return basePrompt
108120
}

0 commit comments

Comments
 (0)