Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find features de...' (#200) from agent/read---spec-code-core-go-i18n-rfc-md-ful into dev
All checks were successful
Security Scan / security (push) Successful in 16s
Test / test (push) Successful in 2m20s

This commit is contained in:
Virgil 2026-04-02 10:29:34 +00:00
commit a72fa80daa
4 changed files with 36 additions and 0 deletions

View file

@ -163,6 +163,11 @@ func (s *CoreService) Raw(messageID string, args ...any) string {
return s.svc.Raw(messageID, args...)
}
// AddMessages adds message strings to the wrapped service.
func (s *CoreService) AddMessages(lang string, messages map[string]string) {
s.svc.AddMessages(lang, messages)
}
// SetLanguage changes the wrapped service language.
func (s *CoreService) SetLanguage(lang string) error {
return s.svc.SetLanguage(lang)

View file

@ -402,6 +402,11 @@ func TestCoreService_DelegatesToWrappedService(t *testing.T) {
"locales/en.json": &fstest.MapFile{Data: []byte(`{"core.service.loaded.fs": "loaded via fs"}`)},
}, "locales"))
assert.Equal(t, "loaded via fs", coreSvc.T("core.service.loaded.fs"))
coreSvc.AddMessages("en", map[string]string{
"core.service.add.messages": "loaded via add messages",
})
assert.Equal(t, "loaded via add messages", coreSvc.T("core.service.add.messages"))
}
func TestInit_ReDetectsRegisteredLocales(t *testing.T) {

View file

@ -244,6 +244,15 @@ func LoadFS(fsys fs.FS, dir string) {
})
}
// AddMessages adds message strings to the default service for a language.
//
// Example:
//
// i18n.AddMessages("en", map[string]string{"custom.greeting": "Hello!"})
func AddMessages(lang string, messages map[string]string) {
withDefaultService(func(svc *Service) { svc.AddMessages(lang, messages) })
}
// PrependHandler inserts one or more handlers at the start of the default service's handler chain.
//
// Example:

View file

@ -108,6 +108,23 @@ func TestLoadFS_Good(t *testing.T) {
assert.Equal(t, "loaded via package helper", got)
}
func TestAddMessages_Good(t *testing.T) {
svc, err := New()
require.NoError(t, err)
prev := Default()
SetDefault(svc)
t.Cleanup(func() {
SetDefault(prev)
})
AddMessages("en", map[string]string{
"add.messages.key": "loaded via package helper",
})
got := T("add.messages.key")
assert.Equal(t, "loaded via package helper", got)
}
// --- SetLanguage / CurrentLanguage ---
func TestSetLanguage_Good(t *testing.T) {