fix(i18n): avoid duplicate lang miss dispatch
All checks were successful
Security Scan / security (push) Successful in 17s
Test / test (push) Successful in 2m29s

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 11:34:08 +00:00
parent 2abe15c2b1
commit e7bbae8d18
2 changed files with 23 additions and 1 deletions

View file

@ -259,7 +259,7 @@ func Lang(key string) string {
}
}
}
return T("lang." + key)
return "lang." + key
}
func normalizeLookupKey(key string) string {

View file

@ -365,6 +365,28 @@ func TestLang_Good(t *testing.T) {
}
}
func TestLang_MissingKeyHandler_FiresOnce(t *testing.T) {
svc, err := New()
require.NoError(t, err)
prev := Default()
SetDefault(svc)
t.Cleanup(func() {
SetMissingKeyHandlers()
SetMode(ModeNormal)
SetDefault(prev)
})
SetMode(ModeCollect)
calls := 0
SetMissingKeyHandlers(func(MissingKey) {
calls++
})
got := Lang("zz")
assert.Equal(t, "[lang.zz]", got)
assert.Equal(t, 1, calls)
}
// --- AddHandler / PrependHandler ---
func TestAddHandler_Good(t *testing.T) {