fix(i18n): avoid duplicate lang miss dispatch
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
2abe15c2b1
commit
e7bbae8d18
2 changed files with 23 additions and 1 deletions
2
i18n.go
2
i18n.go
|
|
@ -259,7 +259,7 @@ func Lang(key string) string {
|
|||
}
|
||||
}
|
||||
}
|
||||
return T("lang." + key)
|
||||
return "lang." + key
|
||||
}
|
||||
|
||||
func normalizeLookupKey(key string) string {
|
||||
|
|
|
|||
22
i18n_test.go
22
i18n_test.go
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue