[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find ONE feature... #95

Merged
Virgil merged 1 commit from agent/read---spec-code-core-go-i18n-rfc-md-ful into dev 2026-04-02 03:08:02 +00:00
2 changed files with 48 additions and 0 deletions

View file

@ -487,6 +487,9 @@ func (s *Service) getEffectiveContextExtra(data any) map[string]any {
switch key {
case "Context", "Gender", "Location", "Formality":
continue
case "Extra", "extra", "Extras", "extras":
mergeContextExtra(extra, value)
continue
default:
extra[key] = value
}
@ -500,6 +503,29 @@ func (s *Service) getEffectiveContextExtra(data any) map[string]any {
}
}
func mergeContextExtra(dst map[string]any, value any) {
if dst == nil || value == nil {
return
}
switch extra := value.(type) {
case map[string]any:
for key, item := range extra {
dst[key] = item
}
case map[string]string:
for key, item := range extra {
dst[key] = item
}
case *TranslationContext:
if extra == nil || len(extra.Extra) == 0 {
return
}
for key, item := range extra.Extra {
dst[key] = item
}
}
}
func (s *Service) getEffectiveFormality(data any) Formality {
if ctx, ok := data.(*TranslationContext); ok && ctx != nil {
if ctx.Formality != FormalityNeutral {

View file

@ -106,6 +106,28 @@ func TestServiceTPluralMessage(t *testing.T) {
}
}
func TestServiceTMapContextNestedExtra(t *testing.T) {
svc, err := New()
if err != nil {
t.Fatalf("New() failed: %v", err)
}
SetDefault(svc)
svc.AddMessages("en", map[string]string{
"welcome._nav._scope._admin": "Admin navigation",
})
got := svc.T("welcome", map[string]any{
"Context": "nav",
"Extra": map[string]any{
"Scope": "admin",
},
})
if got != "Admin navigation" {
t.Fatalf("T(welcome, nested extra) = %q, want %q", got, "Admin navigation")
}
}
func TestServiceRaw(t *testing.T) {
svc, err := New()
if err != nil {