cli/pkg/i18n/debug.go
Snider 1f9321b34b docs(i18n): clarify Set* behaviour and fix CurrentLanguage default
- CurrentLanguage() now returns "en-GB" (fallback) instead of "" when
  service is nil, consistent with other getters returning defaults
- Document why SetLanguage returns error (validates language tag) while
  SetMode, SetFormality, SetDebug do not (just set values)
- Add "Does nothing if service not initialized" to Set* doc comments

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 18:11:03 +00:00

49 lines
1.4 KiB
Go

// 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.
// Does nothing if the service is not initialized.
// 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
}