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 <noreply@anthropic.com>
This commit is contained in:
Snider 2026-01-30 14:57:57 +00:00
parent b2448fa5f2
commit 1477bceb95
3 changed files with 30 additions and 20 deletions

View file

@ -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

View file

@ -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

View file

@ -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.