From 0178ded8fa0c87a45d20873b19c9b86f6985fb69 Mon Sep 17 00:00:00 2001 From: Virgil Date: Wed, 1 Apr 2026 23:38:35 +0000 Subject: [PATCH] fix(service): make Raw use direct lookup only Co-Authored-By: Virgil --- service.go | 11 ++++++++--- service_test.go | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/service.go b/service.go index 325d06e..79fde2d 100644 --- a/service.go +++ b/service.go @@ -330,11 +330,16 @@ func (s *Service) T(messageID string, args ...any) string { return result } -func (s *Service) resolveWithFallback(messageID string, data any) string { +// resolveDirect performs exact-key lookup in the current language and fallback language. +func (s *Service) resolveDirect(messageID string, data any) string { if text := s.tryResolve(s.currentLang, messageID, data); text != "" { return text } - if text := s.tryResolve(s.fallbackLang, messageID, data); text != "" { + return s.tryResolve(s.fallbackLang, messageID, data) +} + +func (s *Service) resolveWithFallback(messageID string, data any) string { + if text := s.resolveDirect(messageID, data); text != "" { return text } if core.Contains(messageID, ".") { @@ -543,7 +548,7 @@ func (s *Service) Raw(messageID string, args ...any) string { if len(args) > 0 { data = args[0] } - text := s.resolveWithFallback(messageID, data) + text := s.resolveDirect(messageID, data) if text == "" { return s.handleMissingKey(messageID, args) } diff --git a/service_test.go b/service_test.go index 19da061..31a28f6 100644 --- a/service_test.go +++ b/service_test.go @@ -126,6 +126,20 @@ func TestServiceRaw(t *testing.T) { } } +func TestServiceRaw_DoesNotUseCommonFallbacks(t *testing.T) { + svc, err := New() + if err != nil { + t.Fatalf("New() failed: %v", err) + } + + svc.messages["en"]["common.action.status"] = Message{Text: "Common status"} + + got := svc.Raw("missing.status") + if got != "missing.status" { + t.Errorf("Raw(missing.status) = %q, want key returned", got) + } +} + func TestServiceModes(t *testing.T) { svc, err := New() if err != nil { -- 2.45.3