diff --git a/pkg/i18n/debug.go b/pkg/i18n/debug.go new file mode 100644 index 00000000..ba273ac8 --- /dev/null +++ b/pkg/i18n/debug.go @@ -0,0 +1,48 @@ +// Package i18n provides internationalization for the CLI. +package i18n + +// Debug mode provides visibility into i18n key resolution for development. +// When enabled, translations are prefixed with their key: [cli.success] Success +// +// Usage: +// +// i18n.SetDebug(true) +// fmt.Println(i18n.T("cli.success")) // "[cli.success] Success" +// +// This helps identify which keys are being used in the UI, making it easier +// to find and update translations during development. + +// SetDebug enables or disables debug mode on the default service. +// In debug mode, translations show their keys: [key] translation +// +// SetDebug(true) +// T("cli.success") // "[cli.success] Success" +func SetDebug(enabled bool) { + if svc := Default(); svc != nil { + svc.SetDebug(enabled) + } +} + +// SetDebug enables or disables debug mode. +// In debug mode, translations are prefixed with their key: +// +// [cli.success] Success +// [core.delete] Delete config.yaml? +func (s *Service) SetDebug(enabled bool) { + s.mu.Lock() + defer s.mu.Unlock() + s.debug = enabled +} + +// Debug returns whether debug mode is enabled. +func (s *Service) Debug() bool { + s.mu.RLock() + defer s.mu.RUnlock() + return s.debug +} + +// debugFormat formats a translation with its key prefix for debug mode. +// Returns "[key] text" format. +func debugFormat(key, text string) string { + return "[" + key + "] " + text +} diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index ab6db0bc..a4286f9e 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -403,17 +403,6 @@ func SetDefault(s *Service) { defaultService = s } -// SetDebug enables or disables debug mode on the default service. -// In debug mode, translations show their keys: [key] translation -// -// SetDebug(true) -// T("cli.success") // "[cli.success] Success" -func SetDebug(enabled bool) { - if svc := Default(); svc != nil { - svc.SetDebug(enabled) - } -} - // SetFormality sets the default formality level on the default service. // // SetFormality(FormalityFormal) // Use formal address (Sie, vous) @@ -563,24 +552,6 @@ func (s *Service) Mode() Mode { return s.mode } -// SetDebug enables or disables debug mode. -// In debug mode, translations are prefixed with their key: -// -// [cli.success] Success -// [core.delete] Delete config.yaml? -func (s *Service) SetDebug(enabled bool) { - s.mu.Lock() - defer s.mu.Unlock() - s.debug = enabled -} - -// Debug returns whether debug mode is enabled. -func (s *Service) Debug() bool { - s.mu.RLock() - defer s.mu.RUnlock() - return s.debug -} - // SetFormality sets the default formality level for translations. // This affects languages that distinguish formal/informal address (Sie/du, vous/tu). // @@ -667,7 +638,7 @@ func (s *Service) T(messageID string, args ...any) string { // Debug mode: prefix with key if s.debug { - return "[" + messageID + "] " + text + return debugFormat(messageID, text) } return text @@ -814,11 +785,10 @@ func (s *Service) C(intent string, subject *Subject) *Composed { debug := s.debug s.mu.RUnlock() if debug { - prefix := "[" + intent + "] " - result.Question = prefix + result.Question - result.Confirm = prefix + result.Confirm - result.Success = prefix + result.Success - result.Failure = prefix + result.Failure + result.Question = debugFormat(intent, result.Question) + result.Confirm = debugFormat(intent, result.Confirm) + result.Success = debugFormat(intent, result.Success) + result.Failure = debugFormat(intent, result.Failure) } return result