[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find features de... #148
2 changed files with 27 additions and 1 deletions
|
|
@ -55,7 +55,9 @@ func WithLocation(location string) Option {
|
|||
|
||||
// WithHandlers sets custom handlers (replaces default handlers).
|
||||
func WithHandlers(handlers ...KeyHandler) Option {
|
||||
return func(s *Service) { s.handlers = handlers }
|
||||
return func(s *Service) {
|
||||
s.handlers = append([]KeyHandler(nil), handlers...)
|
||||
}
|
||||
}
|
||||
|
||||
// WithDefaultHandlers adds the default i18n.* namespace handlers.
|
||||
|
|
|
|||
|
|
@ -33,6 +33,16 @@ func (h serviceMutatingHandler) Handle(key string, args []any, next func() strin
|
|||
return "mutated"
|
||||
}
|
||||
|
||||
type serviceStubHandler struct{}
|
||||
|
||||
func (serviceStubHandler) Match(key string) bool {
|
||||
return key == "custom.stub"
|
||||
}
|
||||
|
||||
func (serviceStubHandler) Handle(key string, args []any, next func() string) string {
|
||||
return "stub"
|
||||
}
|
||||
|
||||
type underscoreLangLoader struct{}
|
||||
|
||||
func (underscoreLangLoader) Languages() []string {
|
||||
|
|
@ -137,6 +147,20 @@ func TestServiceTranslateMissingKey(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewWithHandlersCopiesInputSlice(t *testing.T) {
|
||||
handlers := []KeyHandler{serviceStubHandler{}}
|
||||
svc, err := New(WithHandlers(handlers...))
|
||||
if err != nil {
|
||||
t.Fatalf("New() failed: %v", err)
|
||||
}
|
||||
|
||||
handlers[0] = LabelHandler{}
|
||||
|
||||
if got := svc.T("custom.stub"); got != "stub" {
|
||||
t.Fatalf("T(custom.stub) = %q, want %q", got, "stub")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceTDirectKeys(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue