go-i18n/compose.go
Claude 97f9c758d1
chore(ax): AX compliance sweep — banned imports, naming, Good/Bad/Ugly tests
- compose.go: remove fmt import, use local stringer interface + core.Sprint
- hooks.go: replace stdlib log with dappco.re/go/core/log
- localise.go: replace os.Getenv with core.Env
- loader.go: replace strings.CutPrefix with core.HasPrefix/TrimPrefix
- reversal/tokeniser.go: replace strings.Fields with local splitFields helper
- validate.go: rename sb → builder (AX naming)
- calibrate.go, classify.go: rename cfg → configuration (AX naming)
- numbers.go: rename local fmt variable → numberFormat
- All test files: add Good/Bad/Ugly triads per AX test naming convention

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-31 08:42:40 +01:00

106 lines
2.4 KiB
Go

package i18n
import "dappco.re/go/core"
// stringer is a local interface for values that can describe themselves as a string.
type stringer interface {
String() string
}
// S creates a new Subject with the given noun and value.
//
// S("file", "config.yaml")
// S("file", path).Count(3).In("workspace")
func S(noun string, value any) *Subject {
return &Subject{Noun: noun, Value: value, count: 1}
}
func (s *Subject) Count(n int) *Subject {
if s == nil {
return nil
}
s.count = n
return s
}
func (s *Subject) Gender(g string) *Subject {
if s == nil {
return nil
}
s.gender = g
return s
}
func (s *Subject) In(location string) *Subject {
if s == nil {
return nil
}
s.location = location
return s
}
func (s *Subject) Formal() *Subject {
if s == nil {
return nil
}
s.formality = FormalityFormal
return s
}
func (s *Subject) Informal() *Subject {
if s == nil {
return nil
}
s.formality = FormalityInformal
return s
}
func (s *Subject) SetFormality(f Formality) *Subject {
if s == nil {
return nil
}
s.formality = f
return s
}
func (s *Subject) String() string {
if s == nil {
return ""
}
if v, ok := s.Value.(stringer); ok {
return v.String()
}
return core.Sprint(s.Value)
}
func (s *Subject) IsPlural() bool { return s != nil && s.count != 1 }
func (s *Subject) CountInt() int { if s == nil { return 1 }; return s.count }
func (s *Subject) CountString() string { if s == nil { return "1" }; return core.Sprint(s.count) }
func (s *Subject) GenderString() string { if s == nil { return "" }; return s.gender }
func (s *Subject) LocationString() string { if s == nil { return "" }; return s.location }
func (s *Subject) NounString() string { if s == nil { return "" }; return s.Noun }
func (s *Subject) FormalityString() string {
if s == nil {
return FormalityNeutral.String()
}
return s.formality.String()
}
func (s *Subject) IsFormal() bool { return s != nil && s.formality == FormalityFormal }
func (s *Subject) IsInformal() bool { return s != nil && s.formality == FormalityInformal }
func newTemplateData(s *Subject) templateData {
if s == nil {
return templateData{Count: 1}
}
return templateData{
Subject: s.String(),
Noun: s.Noun,
Count: s.count,
Gender: s.gender,
Location: s.location,
Formality: s.formality,
IsFormal: s.formality == FormalityFormal,
IsPlural: s.count != 1,
Value: s.Value,
}
}