From f10a2b4bdb3bb947a712ad1ee18d1635f4e7421d Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 30 Jan 2026 17:34:45 +0000 Subject: [PATCH] refactor(i18n): remove legacy i18n.{format} shortcuts Use i18n.numeric.* namespace consistently: - i18n.numeric.number - i18n.numeric.decimal - i18n.numeric.percent - i18n.numeric.bytes - i18n.numeric.ordinal - i18n.numeric.ago Co-Authored-By: Claude Opus 4.5 --- pkg/i18n/numbers_test.go | 20 ++++++++++---------- pkg/i18n/service.go | 22 ---------------------- pkg/i18n/time_test.go | 8 ++++---- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/pkg/i18n/numbers_test.go b/pkg/i18n/numbers_test.go index e9bbeccc..4f2e6b3f 100644 --- a/pkg/i18n/numbers_test.go +++ b/pkg/i18n/numbers_test.go @@ -146,28 +146,28 @@ func TestI18nNumberNamespace(t *testing.T) { require.NoError(t, err) SetDefault(svc) - t.Run("i18n.number", func(t *testing.T) { - result := svc.T("i18n.number", 1234567) + t.Run("i18n.numeric.number", func(t *testing.T) { + result := svc.T("i18n.numeric.number", 1234567) assert.Equal(t, "1,234,567", result) }) - t.Run("i18n.decimal", func(t *testing.T) { - result := svc.T("i18n.decimal", 1234.56) + t.Run("i18n.numeric.decimal", func(t *testing.T) { + result := svc.T("i18n.numeric.decimal", 1234.56) assert.Equal(t, "1,234.56", result) }) - t.Run("i18n.percent", func(t *testing.T) { - result := svc.T("i18n.percent", 0.85) + t.Run("i18n.numeric.percent", func(t *testing.T) { + result := svc.T("i18n.numeric.percent", 0.85) assert.Equal(t, "85%", result) }) - t.Run("i18n.bytes", func(t *testing.T) { - result := svc.T("i18n.bytes", 1572864) + t.Run("i18n.numeric.bytes", func(t *testing.T) { + result := svc.T("i18n.numeric.bytes", 1572864) assert.Equal(t, "1.5 MB", result) }) - t.Run("i18n.ordinal", func(t *testing.T) { - result := svc.T("i18n.ordinal", 3) + t.Run("i18n.numeric.ordinal", func(t *testing.T) { + result := svc.T("i18n.numeric.ordinal", 3) assert.Equal(t, "3rd", result) }) } diff --git a/pkg/i18n/service.go b/pkg/i18n/service.go index 2c90f891..f7527b31 100644 --- a/pkg/i18n/service.go +++ b/pkg/i18n/service.go @@ -337,28 +337,6 @@ func (s *Service) handleI18nNamespace(key string, args []any) string { } } - // Legacy i18n.{format} shortcuts (kept for compatibility) - if len(args) > 0 { - switch key { - case "i18n.number": - return FormatNumber(toInt64(args[0])) - case "i18n.decimal": - return FormatDecimal(toFloat64(args[0])) - case "i18n.percent": - return FormatPercent(toFloat64(args[0])) - case "i18n.bytes": - return FormatBytes(toInt64(args[0])) - case "i18n.ordinal": - return FormatOrdinal(toInt(args[0])) - case "i18n.ago": - if len(args) >= 2 { - if unit, ok := args[1].(string); ok { - return FormatAgo(toInt(args[0]), unit) - } - } - } - } - return "" } diff --git a/pkg/i18n/time_test.go b/pkg/i18n/time_test.go index ee2e0f24..41f426c7 100644 --- a/pkg/i18n/time_test.go +++ b/pkg/i18n/time_test.go @@ -73,13 +73,13 @@ func TestI18nAgoNamespace(t *testing.T) { require.NoError(t, err) SetDefault(svc) - t.Run("i18n.ago pattern", func(t *testing.T) { - result := T("i18n.ago", 5, "minute") + t.Run("i18n.numeric.ago pattern", func(t *testing.T) { + result := T("i18n.numeric.ago", 5, "minute") assert.Equal(t, "5 minutes ago", result) }) - t.Run("i18n.ago singular", func(t *testing.T) { - result := T("i18n.ago", 1, "hour") + t.Run("i18n.numeric.ago singular", func(t *testing.T) { + result := T("i18n.numeric.ago", 1, "hour") assert.Equal(t, "1 hour ago", result) }) }