diff --git a/service.go b/service.go index d7c1f15..bac71c6 100644 --- a/service.go +++ b/service.go @@ -403,17 +403,11 @@ func (s *Service) resolveWithFallback(messageID string, data any) string { parts := core.Split(messageID, ".") verb := parts[len(parts)-1] commonKey := "common.action." + verb - if text := s.tryResolve(s.currentLang, commonKey, data); text != "" { - return text - } - if text := s.tryResolve(s.fallbackLang, commonKey, data); text != "" { + if text := s.resolveDirect(commonKey, data); text != "" { return text } commonKey = "common." + verb - if text := s.tryResolve(s.currentLang, commonKey, data); text != "" { - return text - } - if text := s.tryResolve(s.fallbackLang, commonKey, data); text != "" { + if text := s.resolveDirect(commonKey, data); text != "" { return text } } diff --git a/service_test.go b/service_test.go index fce4a14..7f7a8ad 100644 --- a/service_test.go +++ b/service_test.go @@ -296,6 +296,29 @@ func TestServiceMessageFallbackUsesBaseLanguageTagBeforeConfiguredFallback(t *te } } +func TestServiceCommonFallbackUsesBaseLanguageTagBeforeConfiguredFallback(t *testing.T) { + svc, err := NewWithLoader(messageBaseFallbackLoader{}) + if err != nil { + t.Fatalf("NewWithLoader() failed: %v", err) + } + + svc.AddMessages("en", map[string]string{ + "common.action.status": "Common status", + }) + svc.AddMessages("fr", map[string]string{ + "common.action.status": "Statut commun", + }) + + if err := svc.SetLanguage("en-GB"); err != nil { + t.Fatalf("SetLanguage(en-GB) failed: %v", err) + } + svc.SetFallback("fr") + + if got := svc.T("missing.status"); got != "Common status" { + t.Fatalf("T(missing.status) = %q, want %q", got, "Common status") + } +} + func TestServiceDebug(t *testing.T) { svc, err := New() if err != nil {