From 1477bceb958ec487db66131105623f1c373aa57a Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 30 Jan 2026 14:57:57 +0000 Subject: [PATCH] refactor(i18n): consolidate interfaces in interface.go Move MissingKeyHandler, MissingKey, MissingKeyAction, and PluralRule function types to interface.go for better discoverability. Co-Authored-By: Claude Opus 4.5 --- pkg/i18n/interface.go | 30 ++++++++++++++++++++++++++++++ pkg/i18n/language.go | 4 ---- pkg/i18n/mode.go | 16 ---------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/pkg/i18n/interface.go b/pkg/i18n/interface.go index 5edddb6c..eb70ccb6 100644 --- a/pkg/i18n/interface.go +++ b/pkg/i18n/interface.go @@ -78,3 +78,33 @@ type Translator interface { // Ensure Service implements Translator at compile time. var _ Translator = (*Service)(nil) + +// --- Function type interfaces --- + +// MissingKeyHandler receives missing key events for analysis. +// Used in ModeCollect to capture translation keys that need to be added. +// +// i18n.OnMissingKey(func(m i18n.MissingKey) { +// log.Printf("MISSING: %s at %s:%d", m.Key, m.CallerFile, m.CallerLine) +// }) +type MissingKeyHandler func(missing MissingKey) + +// MissingKey is dispatched when a translation key is not found in ModeCollect. +// Used by QA tools to collect and report missing translations. +type MissingKey struct { + Key string // The missing translation key + Args map[string]any // Arguments passed to the translation + CallerFile string // Source file where T()/C() was called + CallerLine int // Line number where T()/C() was called +} + +// MissingKeyAction is an alias for backwards compatibility. +// Deprecated: Use MissingKey instead. +type MissingKeyAction = MissingKey + +// PluralRule is a function that determines the plural category for a count. +// Each language has its own plural rule based on CLDR data. +// +// rule := i18n.GetPluralRule("ru") +// category := rule(5) // Returns PluralMany for Russian +type PluralRule func(n int) PluralCategory diff --git a/pkg/i18n/language.go b/pkg/i18n/language.go index 5979ca45..3f316c6b 100644 --- a/pkg/i18n/language.go +++ b/pkg/i18n/language.go @@ -115,10 +115,6 @@ func (g GrammaticalGender) String() string { } } -// PluralRule is a function that determines the plural category for a count. -// Each language has its own plural rule based on CLDR data. -type PluralRule func(n int) PluralCategory - // rtlLanguages contains language codes that use right-to-left text direction. var rtlLanguages = map[string]bool{ "ar": true, // Arabic diff --git a/pkg/i18n/mode.go b/pkg/i18n/mode.go index 5c561926..343643ee 100644 --- a/pkg/i18n/mode.go +++ b/pkg/i18n/mode.go @@ -31,22 +31,6 @@ func (m Mode) String() string { } } -// MissingKey is dispatched when a translation key is not found in ModeCollect. -// Used by QA tools to collect and report missing translations. -type MissingKey struct { - Key string // The missing translation key - Args map[string]any // Arguments passed to the translation - CallerFile string // Source file where T()/C() was called - CallerLine int // Line number where T()/C() was called -} - -// MissingKeyAction is an alias for backwards compatibility. -// Deprecated: Use MissingKey instead. -type MissingKeyAction = MissingKey - -// MissingKeyHandler receives missing key events for analysis. -type MissingKeyHandler func(missing MissingKey) - var missingKeyHandler MissingKeyHandler // OnMissingKey registers a handler for missing translation keys.