From 295726862901ba38a648cd04f04646f118b99f1a Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 02:09:50 +0000 Subject: [PATCH] Apply default location to map translations --- service.go | 2 +- service_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/service.go b/service.go index 6f21ecd..c4fd078 100644 --- a/service.go +++ b/service.go @@ -440,7 +440,7 @@ func (s *Service) getEffectiveContextGenderLocationAndFormality(data any) (strin if m, ok := data.(map[string]any); ok { var context string var gender string - var location string + location := s.location formality := s.formality if v, ok := m["Context"].(string); ok { context = core.Trim(v) diff --git a/service_test.go b/service_test.go index e32cce9..47df379 100644 --- a/service_test.go +++ b/service_test.go @@ -349,6 +349,22 @@ func TestServiceTranslationContextExtrasInLookup(t *testing.T) { } } +func TestServiceDefaultLocationAppliesToMapData(t *testing.T) { + svc, err := New() + if err != nil { + t.Fatalf("New() failed: %v", err) + } + + svc.AddMessages("en", map[string]string{ + "welcome._workspace": "welcome aboard", + }) + svc.SetLocation("workspace") + + if got := svc.T("welcome", map[string]any{}); got != "welcome aboard" { + t.Errorf("T(welcome, map[]) with default location = %q, want %q", got, "welcome aboard") + } +} + func TestServiceSubjectCountPlurals(t *testing.T) { svc, err := New() if err != nil { -- 2.45.3