[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find ONE feature... #25
3 changed files with 39 additions and 10 deletions
12
i18n.go
12
i18n.go
|
|
@ -71,17 +71,17 @@ func N(format string, value any) string {
|
|||
return T("i18n.numeric."+format, value)
|
||||
}
|
||||
|
||||
// AddHandler appends a handler to the default service's handler chain.
|
||||
func AddHandler(h KeyHandler) {
|
||||
// AddHandler appends one or more handlers to the default service's handler chain.
|
||||
func AddHandler(handlers ...KeyHandler) {
|
||||
if svc := Default(); svc != nil {
|
||||
svc.AddHandler(h)
|
||||
svc.AddHandler(handlers...)
|
||||
}
|
||||
}
|
||||
|
||||
// PrependHandler inserts a handler at the start of the default service's handler chain.
|
||||
func PrependHandler(h KeyHandler) {
|
||||
// PrependHandler inserts one or more handlers at the start of the default service's handler chain.
|
||||
func PrependHandler(handlers ...KeyHandler) {
|
||||
if svc := Default(); svc != nil {
|
||||
svc.PrependHandler(h)
|
||||
svc.PrependHandler(handlers...)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
26
i18n_test.go
26
i18n_test.go
|
|
@ -159,6 +159,19 @@ func TestAddHandler_Good(t *testing.T) {
|
|||
assert.Equal(t, initialCount+1, len(svc.Handlers()))
|
||||
}
|
||||
|
||||
func TestAddHandler_Good_Variadic(t *testing.T) {
|
||||
svc, err := New(WithHandlers())
|
||||
require.NoError(t, err)
|
||||
_ = Init()
|
||||
SetDefault(svc)
|
||||
|
||||
AddHandler(LabelHandler{}, ProgressHandler{})
|
||||
handlers := svc.Handlers()
|
||||
assert.Equal(t, 2, len(handlers))
|
||||
assert.IsType(t, LabelHandler{}, handlers[0])
|
||||
assert.IsType(t, ProgressHandler{}, handlers[1])
|
||||
}
|
||||
|
||||
func TestPrependHandler_Good(t *testing.T) {
|
||||
svc, err := New(WithHandlers()) // start with no handlers
|
||||
require.NoError(t, err)
|
||||
|
|
@ -174,6 +187,19 @@ func TestPrependHandler_Good(t *testing.T) {
|
|||
assert.Equal(t, 2, len(handlers))
|
||||
}
|
||||
|
||||
func TestPrependHandler_Good_Variadic(t *testing.T) {
|
||||
svc, err := New(WithHandlers())
|
||||
require.NoError(t, err)
|
||||
_ = Init()
|
||||
SetDefault(svc)
|
||||
|
||||
PrependHandler(LabelHandler{}, ProgressHandler{})
|
||||
handlers := svc.Handlers()
|
||||
assert.Equal(t, 2, len(handlers))
|
||||
assert.IsType(t, LabelHandler{}, handlers[0])
|
||||
assert.IsType(t, ProgressHandler{}, handlers[1])
|
||||
}
|
||||
|
||||
// --- executeIntentTemplate ---
|
||||
|
||||
func TestExecuteIntentTemplate_Good(t *testing.T) {
|
||||
|
|
|
|||
11
service.go
11
service.go
|
|
@ -262,16 +262,19 @@ func (s *Service) PluralCategory(n int) PluralCategory {
|
|||
return GetPluralCategory(s.currentLang, n)
|
||||
}
|
||||
|
||||
func (s *Service) AddHandler(h KeyHandler) {
|
||||
func (s *Service) AddHandler(handlers ...KeyHandler) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.handlers = append(s.handlers, h)
|
||||
s.handlers = append(s.handlers, handlers...)
|
||||
}
|
||||
|
||||
func (s *Service) PrependHandler(h KeyHandler) {
|
||||
func (s *Service) PrependHandler(handlers ...KeyHandler) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
s.handlers = append([]KeyHandler{h}, s.handlers...)
|
||||
if len(handlers) == 0 {
|
||||
return
|
||||
}
|
||||
s.handlers = append(append([]KeyHandler(nil), handlers...), s.handlers...)
|
||||
}
|
||||
|
||||
func (s *Service) ClearHandlers() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue