[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find features de... #134
2 changed files with 43 additions and 3 deletions
|
|
@ -771,16 +771,17 @@ func missingKeySubjectArgs(subj *Subject) map[string]any {
|
|||
// Raw translates without i18n.* namespace magic.
|
||||
func (s *Service) Raw(messageID string, args ...any) string {
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
var data any
|
||||
if len(args) > 0 {
|
||||
data = args[0]
|
||||
}
|
||||
text := s.resolveDirectLocked(messageID, data)
|
||||
debug := s.debug
|
||||
s.mu.RUnlock()
|
||||
if text == "" {
|
||||
return s.handleMissingKey(messageID, args)
|
||||
text = s.handleMissingKey(messageID, args)
|
||||
}
|
||||
if s.debug {
|
||||
if debug {
|
||||
return debugFormat(messageID, text)
|
||||
}
|
||||
return text
|
||||
|
|
|
|||
|
|
@ -275,6 +275,45 @@ func TestServiceRaw_DoesNotUseCommonFallbacks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestServiceRaw_MissingKeyHandlersCanMutateService(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
t.Fatalf("New() failed: %v", err)
|
||||
}
|
||||
|
||||
prev := missingKeyHandlers()
|
||||
t.Cleanup(func() {
|
||||
missingKeyHandler.Store(prev)
|
||||
})
|
||||
|
||||
OnMissingKey(func(m MissingKey) {
|
||||
_ = svc.SetLanguage("fr")
|
||||
})
|
||||
svc.SetMode(ModeCollect)
|
||||
svc.SetDebug(true)
|
||||
t.Cleanup(func() {
|
||||
svc.SetDebug(false)
|
||||
})
|
||||
|
||||
done := make(chan string, 1)
|
||||
go func() {
|
||||
done <- svc.Raw("missing.raw.key")
|
||||
}()
|
||||
|
||||
select {
|
||||
case got := <-done:
|
||||
if got != "[missing.raw.key] [missing.raw.key]" {
|
||||
t.Fatalf("Raw(missing.raw.key) = %q, want %q", got, "[missing.raw.key] [missing.raw.key]")
|
||||
}
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("Raw(missing.raw.key) timed out while missing-key handler mutated service state")
|
||||
}
|
||||
|
||||
if got := svc.Language(); got != "fr" {
|
||||
t.Fatalf("Language() = %q, want %q", got, "fr")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceModes(t *testing.T) {
|
||||
svc, err := New()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue