From c47c2905a8da8f4bcb8be999251c7857ea2c7d1b Mon Sep 17 00:00:00 2001 From: Snider Date: Fri, 30 Jan 2026 18:15:28 +0000 Subject: [PATCH] refactor(i18n): consistent empty input handling and add doc comment - Article("") now returns "" for consistency with other grammar functions (PastTense, Gerund, PluralForm, Label all return "") - Add doc comment to getMessage() for consistency with other internal helpers Co-Authored-By: Claude Opus 4.5 --- pkg/i18n/grammar.go | 2 +- pkg/i18n/grammar_test.go | 2 +- pkg/i18n/service.go | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/i18n/grammar.go b/pkg/i18n/grammar.go index 317156fa..cc1b3f26 100644 --- a/pkg/i18n/grammar.go +++ b/pkg/i18n/grammar.go @@ -356,7 +356,7 @@ func applyRegularPlural(noun string) string { // Article("hour") // "an" (silent h) func Article(word string) string { if word == "" { - return "a" + return "" } lower := strings.ToLower(strings.TrimSpace(word)) diff --git a/pkg/i18n/grammar_test.go b/pkg/i18n/grammar_test.go index 0cc56da6..00780f23 100644 --- a/pkg/i18n/grammar_test.go +++ b/pkg/i18n/grammar_test.go @@ -243,7 +243,7 @@ func TestArticle(t *testing.T) { {"heir", "an"}, // Edge cases - {"", "a"}, + {"", ""}, {" error ", "an"}, } diff --git a/pkg/i18n/service.go b/pkg/i18n/service.go index 5e937b08..bb5f9f4f 100644 --- a/pkg/i18n/service.go +++ b/pkg/i18n/service.go @@ -491,6 +491,8 @@ func (s *Service) Raw(messageID string, args ...any) string { return text } +// getMessage retrieves a message by language and key. +// Returns the message and true if found, or empty Message and false if not. func (s *Service) getMessage(lang, key string) (Message, bool) { msgs, ok := s.messages[lang] if !ok {