From c78f1d9df10b3c2b42196ed261ac3128efd016bd Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 30 Jan 2026 17:00:05 +0000 Subject: [PATCH] refactor(i18n): move ForCategory to interface.go Keep Message method with its type definition. Co-Authored-By: Claude Opus 4.5 --- pkg/i18n/i18n.go | 35 ----------------------------------- pkg/i18n/interface.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/pkg/i18n/i18n.go b/pkg/i18n/i18n.go index 0f8bbf67..851d0abc 100644 --- a/pkg/i18n/i18n.go +++ b/pkg/i18n/i18n.go @@ -34,41 +34,6 @@ import ( //go:embed locales/*.json var localeFS embed.FS -// ForCategory returns the appropriate text for a plural category. -// Falls back through the category hierarchy to find a non-empty string. -func (m Message) ForCategory(cat PluralCategory) string { - switch cat { - case PluralZero: - if m.Zero != "" { - return m.Zero - } - case PluralOne: - if m.One != "" { - return m.One - } - case PluralTwo: - if m.Two != "" { - return m.Two - } - case PluralFew: - if m.Few != "" { - return m.Few - } - case PluralMany: - if m.Many != "" { - return m.Many - } - } - // Fallback to Other, then One, then Text - if m.Other != "" { - return m.Other - } - if m.One != "" { - return m.One - } - return m.Text -} - // --- Global convenience functions --- // T translates a message using the default service. diff --git a/pkg/i18n/interface.go b/pkg/i18n/interface.go index 0fddc2ec..e8361b40 100644 --- a/pkg/i18n/interface.go +++ b/pkg/i18n/interface.go @@ -114,3 +114,38 @@ type Message struct { Many string // Larger numbers (Slavic: 5+, Arabic: 11-99) Other string // Default/fallback form } + +// ForCategory returns the appropriate text for a plural category. +// Falls back through the category hierarchy to find a non-empty string. +func (m Message) ForCategory(cat PluralCategory) string { + switch cat { + case PluralZero: + if m.Zero != "" { + return m.Zero + } + case PluralOne: + if m.One != "" { + return m.One + } + case PluralTwo: + if m.Two != "" { + return m.Two + } + case PluralFew: + if m.Few != "" { + return m.Few + } + case PluralMany: + if m.Many != "" { + return m.Many + } + } + // Fallback to Other, then One, then Text + if m.Other != "" { + return m.Other + } + if m.One != "" { + return m.One + } + return m.Text +}