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 <noreply@anthropic.com>
This commit is contained in:
Snider 2026-01-30 18:15:28 +00:00
parent 1f9321b34b
commit c47c2905a8
3 changed files with 4 additions and 2 deletions

View file

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

View file

@ -243,7 +243,7 @@ func TestArticle(t *testing.T) {
{"heir", "an"},
// Edge cases
{"", "a"},
{"", ""},
{" error ", "an"},
}

View file

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