From d868f21ab222f5f1c79a3beddb649986e7083e67 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 13:06:07 +0000 Subject: [PATCH] feat(i18n): enrich service state snapshot Co-Authored-By: Virgil --- i18n.go | 2 ++ service_test.go | 8 ++++++++ state.go | 10 +++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/i18n.go b/i18n.go index 7f83c04..2b2e0ed 100644 --- a/i18n.go +++ b/i18n.go @@ -182,6 +182,8 @@ func CurrentDebug() bool { func State() ServiceState { return defaultServiceValue(ServiceState{ Language: "en", + RequestedLanguage: "", + LanguageExplicit: false, AvailableLanguages: []string{}, Mode: ModeNormal, Fallback: "en", diff --git a/service_test.go b/service_test.go index c0598dd..e151569 100644 --- a/service_test.go +++ b/service_test.go @@ -193,6 +193,12 @@ func TestServiceCurrentStateAliases(t *testing.T) { if got, want := svc.CurrentState(), svc.State(); len(got.AvailableLanguages) != len(want.AvailableLanguages) || len(got.Handlers) != len(want.Handlers) { t.Fatalf("CurrentState() = %+v, want %+v", got, want) } + if got, want := svc.CurrentState().RequestedLanguage, svc.State().RequestedLanguage; got != want { + t.Fatalf("CurrentState().RequestedLanguage = %q, want %q", got, want) + } + if got, want := svc.CurrentState().LanguageExplicit, svc.State().LanguageExplicit; got != want { + t.Fatalf("CurrentState().LanguageExplicit = %t, want %t", got, want) + } } func TestServiceCurrentStateAliasesReturnCopies(t *testing.T) { @@ -249,6 +255,8 @@ func TestServiceStateString(t *testing.T) { for _, want := range []string{ "ServiceState{", "language=", + "requested=", + "explicit=", "fallback=", "mode=", "available=", diff --git a/state.go b/state.go index d1b53ca..2a4013f 100644 --- a/state.go +++ b/state.go @@ -8,6 +8,8 @@ import ( // copy-safe snapshot. type ServiceState struct { Language string + RequestedLanguage string + LanguageExplicit bool AvailableLanguages []string Mode Mode Fallback string @@ -38,8 +40,10 @@ func (s ServiceState) String() string { handlers = "[" + core.Join(", ", names...) + "]" } return core.Sprintf( - "ServiceState{language=%q fallback=%q mode=%s formality=%s location=%q direction=%s rtl=%t debug=%t available=%s handlers=%d types=%s}", + "ServiceState{language=%q requested=%q explicit=%t fallback=%q mode=%s formality=%s location=%q direction=%s rtl=%t debug=%t available=%s handlers=%d types=%s}", s.Language, + s.RequestedLanguage, + s.LanguageExplicit, s.Fallback, s.Mode, s.Formality, @@ -57,6 +61,8 @@ func (s *Service) State() ServiceState { if s == nil { return ServiceState{ Language: "en", + RequestedLanguage: "", + LanguageExplicit: false, AvailableLanguages: []string{}, Mode: ModeNormal, Fallback: "en", @@ -85,6 +91,8 @@ func (s *Service) State() ServiceState { return ServiceState{ Language: s.currentLang, + RequestedLanguage: s.requestedLang, + LanguageExplicit: s.languageExplicit, AvailableLanguages: langs, Mode: s.mode, Fallback: s.fallbackLang,