refactor(i18n): remove deprecated backwards-compat code
Remove since this is a new package with no external users: - SetActionHandler() - use OnMissingKey() instead - MissingKeyAction type alias - use MissingKey instead Update tests to use current API. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
650c7b1c5a
commit
7b9f23dd9e
3 changed files with 18 additions and 29 deletions
|
|
@ -18,12 +18,6 @@ func OnMissingKey(h MissingKeyHandler) {
|
|||
missingKeyHandler = h
|
||||
}
|
||||
|
||||
// SetActionHandler registers a handler for missing key dispatches.
|
||||
// Deprecated: Use OnMissingKey instead.
|
||||
func SetActionHandler(h func(action MissingKeyAction)) {
|
||||
OnMissingKey(h)
|
||||
}
|
||||
|
||||
// dispatchMissingKey creates and dispatches a MissingKey event.
|
||||
// Called internally when a key is missing in ModeCollect.
|
||||
func dispatchMissingKey(key string, args map[string]any) {
|
||||
|
|
|
|||
|
|
@ -486,10 +486,6 @@ type MissingKey struct {
|
|||
CallerLine int // Line number where T() was called
|
||||
}
|
||||
|
||||
// MissingKeyAction is an alias for backwards compatibility.
|
||||
// Deprecated: Use MissingKey instead.
|
||||
type MissingKeyAction = MissingKey
|
||||
|
||||
// PluralRule is a function that determines the plural category for a count.
|
||||
// Each language has its own plural rule based on CLDR data.
|
||||
//
|
||||
|
|
|
|||
|
|
@ -26,28 +26,28 @@ func TestMode_String(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMissingKeyAction(t *testing.T) {
|
||||
action := MissingKeyAction{
|
||||
func TestMissingKey(t *testing.T) {
|
||||
mk := MissingKey{
|
||||
Key: "test.missing.key",
|
||||
Args: map[string]any{"Name": "test"},
|
||||
CallerFile: "/path/to/file.go",
|
||||
CallerLine: 42,
|
||||
}
|
||||
|
||||
assert.Equal(t, "test.missing.key", action.Key)
|
||||
assert.Equal(t, "test", action.Args["Name"])
|
||||
assert.Equal(t, "/path/to/file.go", action.CallerFile)
|
||||
assert.Equal(t, 42, action.CallerLine)
|
||||
assert.Equal(t, "test.missing.key", mk.Key)
|
||||
assert.Equal(t, "test", mk.Args["Name"])
|
||||
assert.Equal(t, "/path/to/file.go", mk.CallerFile)
|
||||
assert.Equal(t, 42, mk.CallerLine)
|
||||
}
|
||||
|
||||
func TestSetActionHandler(t *testing.T) {
|
||||
func TestOnMissingKey(t *testing.T) {
|
||||
// Reset handler after test
|
||||
defer SetActionHandler(nil)
|
||||
defer OnMissingKey(nil)
|
||||
|
||||
t.Run("sets handler", func(t *testing.T) {
|
||||
var received MissingKeyAction
|
||||
SetActionHandler(func(action MissingKeyAction) {
|
||||
received = action
|
||||
var received MissingKey
|
||||
OnMissingKey(func(mk MissingKey) {
|
||||
received = mk
|
||||
})
|
||||
|
||||
dispatchMissingKey("test.key", map[string]any{"foo": "bar"})
|
||||
|
|
@ -57,7 +57,7 @@ func TestSetActionHandler(t *testing.T) {
|
|||
})
|
||||
|
||||
t.Run("nil handler", func(t *testing.T) {
|
||||
SetActionHandler(nil)
|
||||
OnMissingKey(nil)
|
||||
// Should not panic
|
||||
dispatchMissingKey("test.key", nil)
|
||||
})
|
||||
|
|
@ -66,10 +66,10 @@ func TestSetActionHandler(t *testing.T) {
|
|||
called1 := false
|
||||
called2 := false
|
||||
|
||||
SetActionHandler(func(action MissingKeyAction) {
|
||||
OnMissingKey(func(mk MissingKey) {
|
||||
called1 = true
|
||||
})
|
||||
SetActionHandler(func(action MissingKeyAction) {
|
||||
OnMissingKey(func(mk MissingKey) {
|
||||
called2 = true
|
||||
})
|
||||
|
||||
|
|
@ -138,16 +138,16 @@ func TestModeStrict_MissingKey(t *testing.T) {
|
|||
|
||||
func TestModeCollect_MissingKey(t *testing.T) {
|
||||
// Reset handler after test
|
||||
defer SetActionHandler(nil)
|
||||
defer OnMissingKey(nil)
|
||||
|
||||
svc, err := New()
|
||||
require.NoError(t, err)
|
||||
|
||||
svc.SetMode(ModeCollect)
|
||||
|
||||
var received MissingKeyAction
|
||||
SetActionHandler(func(action MissingKeyAction) {
|
||||
received = action
|
||||
var received MissingKey
|
||||
OnMissingKey(func(mk MissingKey) {
|
||||
received = mk
|
||||
})
|
||||
|
||||
// Missing key should dispatch action and return [key]
|
||||
|
|
@ -159,4 +159,3 @@ func TestModeCollect_MissingKey(t *testing.T) {
|
|||
assert.NotEmpty(t, received.CallerFile)
|
||||
assert.Greater(t, received.CallerLine, 0)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue