From fdb151a0afc1d3c455ff7d7883e62cd9dfbf86d8 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 13:38:04 +0000 Subject: [PATCH] fix(i18n): keep default state snapshot explicit Co-Authored-By: Virgil --- i18n.go | 5 +++-- i18n_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/i18n.go b/i18n.go index 5ae3398..6076d8e 100644 --- a/i18n.go +++ b/i18n.go @@ -180,9 +180,10 @@ func CurrentDebug() bool { // State returns a copy-safe snapshot of the default service configuration. func State() ServiceState { - return defaultServiceValue(defaultServiceStateSnapshot(), func(svc *Service) ServiceState { + if svc := Default(); svc != nil { return svc.State() - }) + } + return defaultServiceStateSnapshot() } // CurrentState is a more explicit alias for State. diff --git a/i18n_test.go b/i18n_test.go index a01598c..e6cb6b3 100644 --- a/i18n_test.go +++ b/i18n_test.go @@ -261,6 +261,12 @@ func TestCurrentState_Good(t *testing.T) { assert.NotNil(t, CurrentState().Handlers[0]) } +func TestState_Good_WithoutDefaultService(t *testing.T) { + var svc *Service + state := svc.State() + assert.Equal(t, defaultServiceStateSnapshot(), state) +} + // --- SetMode / CurrentMode --- func TestSetMode_Good(t *testing.T) {