[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/i18n/RFC.md fully. Find features de... #156
6 changed files with 21 additions and 19 deletions
10
compose.go
10
compose.go
|
|
@ -1,6 +1,10 @@
|
|||
package i18n
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"dappco.re/go/core"
|
||||
)
|
||||
|
||||
// S creates a new Subject with the given noun and value.
|
||||
//
|
||||
|
|
@ -82,7 +86,7 @@ func (s *Subject) String() string {
|
|||
if stringer, ok := s.Value.(fmt.Stringer); ok {
|
||||
return stringer.String()
|
||||
}
|
||||
return fmt.Sprint(s.Value)
|
||||
return core.Sprintf("%v", s.Value)
|
||||
}
|
||||
|
||||
func (s *Subject) IsPlural() bool { return s != nil && s.count != 1 }
|
||||
|
|
@ -96,7 +100,7 @@ func (s *Subject) CountString() string {
|
|||
if s == nil {
|
||||
return "1"
|
||||
}
|
||||
return fmt.Sprint(s.count)
|
||||
return core.Sprintf("%d", s.count)
|
||||
}
|
||||
func (s *Subject) GenderString() string {
|
||||
if s == nil {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package i18n
|
||||
|
||||
import "fmt"
|
||||
|
||||
// TranslationContext provides disambiguation for translations.
|
||||
//
|
||||
// T("direction.right", C("navigation")) // "rechts" (German)
|
||||
|
|
@ -88,7 +86,7 @@ func (c *TranslationContext) String() string {
|
|||
if c == nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprint(c.Context)
|
||||
return c.Context
|
||||
}
|
||||
|
||||
func (c *TranslationContext) GenderString() string {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package i18n
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"dappco.re/go/core"
|
||||
|
|
@ -184,7 +183,7 @@ func isPluralisableWordDisplay(s string) bool {
|
|||
}
|
||||
|
||||
func isUpperAcronymPlural(s string) bool {
|
||||
if len(s) < 2 || !strings.HasSuffix(s, "s") {
|
||||
if len(s) < 2 || !core.HasSuffix(s, "s") {
|
||||
return false
|
||||
}
|
||||
hasLetter := false
|
||||
|
|
|
|||
13
hooks.go
13
hooks.go
|
|
@ -2,11 +2,12 @@ package i18n
|
|||
|
||||
import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"dappco.re/go/core"
|
||||
log "dappco.re/go/core/log"
|
||||
)
|
||||
|
||||
var missingKeyHandler atomic.Value
|
||||
|
|
@ -59,7 +60,7 @@ func RegisterLocales(fsys fs.FS, dir string) {
|
|||
registeredLocalesMu.Unlock()
|
||||
if svc != nil {
|
||||
if err := svc.LoadFS(fsys, dir); err != nil {
|
||||
log.Printf("i18n: RegisterLocales failed to load %q: %v", dir, err)
|
||||
log.Error("i18n: RegisterLocales failed to load", "dir", dir, "err", err)
|
||||
} else {
|
||||
svc.markLocaleRegistrationLoaded(reg.id)
|
||||
}
|
||||
|
|
@ -99,7 +100,7 @@ func loadRegisteredLocales(svc *Service) {
|
|||
continue
|
||||
}
|
||||
if err := svc.LoadFS(reg.fsys, reg.dir); err != nil {
|
||||
log.Printf("i18n: loadRegisteredLocales failed to load %q: %v", reg.dir, err)
|
||||
log.Error("i18n: loadRegisteredLocales failed to load", "dir", reg.dir, "err", err)
|
||||
continue
|
||||
}
|
||||
svc.markLocaleRegistrationLoaded(reg.id)
|
||||
|
|
@ -122,7 +123,7 @@ func loadLocaleProvider(svc *Service, provider localeProviderRegistration) {
|
|||
}
|
||||
for _, src := range provider.provider.LocaleSources() {
|
||||
if err := svc.LoadFS(src.FS, src.Dir); err != nil {
|
||||
log.Printf("i18n: loadLocaleProvider failed to load %q: %v", src.Dir, err)
|
||||
log.Error("i18n: loadLocaleProvider failed to load", "dir", src.Dir, "err", err)
|
||||
}
|
||||
}
|
||||
svc.markLocaleProviderLoaded(provider.id)
|
||||
|
|
@ -191,7 +192,7 @@ func missingKeyCaller() (string, int) {
|
|||
frames := runtime.CallersFrames(pcs[:n])
|
||||
for {
|
||||
frame, more := frames.Next()
|
||||
if !strings.HasPrefix(frame.Function, packagePrefix) || strings.HasSuffix(frame.File, "_test.go") {
|
||||
if !core.HasPrefix(frame.Function, packagePrefix) || core.HasSuffix(frame.File, "_test.go") {
|
||||
return frame.File, frame.Line
|
||||
}
|
||||
if !more {
|
||||
|
|
|
|||
3
i18n.go
3
i18n.go
|
|
@ -3,7 +3,6 @@ package i18n
|
|||
import (
|
||||
"bytes"
|
||||
"io/fs"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"dappco.re/go/core"
|
||||
|
|
@ -151,7 +150,7 @@ func Lang(key string) string {
|
|||
if got := T("lang." + key); got != "lang."+key {
|
||||
return got
|
||||
}
|
||||
if idx := strings.IndexAny(key, "-_"); idx > 0 {
|
||||
if idx := indexAny(key, "-_"); idx > 0 {
|
||||
if base := key[:idx]; base != "" {
|
||||
if got := T("lang." + base); got != "lang."+base {
|
||||
return got
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"io/fs"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"dappco.re/go/core"
|
||||
|
|
@ -136,7 +135,8 @@ func flattenWithGrammar(prefix string, data map[string]any, out map[string]Messa
|
|||
if base, ok := v["base"].(string); ok && base != "" {
|
||||
verbName = base
|
||||
}
|
||||
if after, ok := strings.CutPrefix(fullKey, "gram.verb."); ok {
|
||||
if core.HasPrefix(fullKey, "gram.verb.") {
|
||||
after := core.TrimPrefix(fullKey, "gram.verb.")
|
||||
if base, ok := v["base"].(string); !ok || base == "" {
|
||||
verbName = after
|
||||
}
|
||||
|
|
@ -155,7 +155,8 @@ func flattenWithGrammar(prefix string, data map[string]any, out map[string]Messa
|
|||
// Noun form object (under gram.noun.* or has gender field)
|
||||
if grammar != nil && (core.HasPrefix(fullKey, "gram.noun.") || isNounFormObject(v)) {
|
||||
nounName := key
|
||||
if after, ok := strings.CutPrefix(fullKey, "gram.noun."); ok {
|
||||
if core.HasPrefix(fullKey, "gram.noun.") {
|
||||
after := core.TrimPrefix(fullKey, "gram.noun.")
|
||||
nounName = after
|
||||
}
|
||||
if shouldSkipDeprecatedEnglishGrammarEntry(fullKey) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue