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

Merged
Virgil merged 1 commit from agent/read---spec-code-core-go-i18n-rfc-md-ful into dev 2026-04-02 02:42:42 +00:00
6 changed files with 7 additions and 17 deletions

View file

@ -216,7 +216,7 @@ Locale-aware number formatting.
T("i18n.numeric.number", 1234567) // "1,234,567"
T("i18n.numeric.decimal", 3.14) // "3.14"
T("i18n.numeric.percent", 0.85) // "85%"
T("i18n.numeric.bytes", 1536000) // "1.5 MB"
T("i18n.numeric.bytes", 1536000) // "1.46 MB"
T("i18n.numeric.ordinal", 3) // "3rd"
T("i18n.numeric.ago", 5, "minutes") // "5 minutes ago"
```
@ -226,7 +226,7 @@ The shorthand `N()` function wraps this namespace:
```go
i18n.N("number", 1234567) // "1,234,567"
i18n.N("percent", 0.85) // "85%"
i18n.N("bytes", 1536000) // "1.5 MB"
i18n.N("bytes", 1536000) // "1.46 MB"
i18n.N("ordinal", 1) // "1st"
```

View file

@ -188,7 +188,7 @@ func TestNumericHandler(t *testing.T) {
{"i18n.numeric.ordinal", []any{3}, "3rd"},
{"i18n.numeric.ordinal", []any{11}, "11th"},
{"i18n.numeric.percent", []any{0.85}, "85%"},
{"i18n.numeric.bytes", []any{int64(1536000)}, "1.5 MB"},
{"i18n.numeric.bytes", []any{int64(1536000)}, "1.46 MB"},
{"i18n.numeric.ago", []any{5, "minutes"}, "5 minutes ago"},
}

View file

@ -81,7 +81,7 @@ func CurrentDebug() bool {
//
// N("number", 1234567) // "1,234,567"
// N("percent", 0.85) // "85%"
// N("bytes", 1536000) // "1.5 MB"
// N("bytes", 1536000) // "1.46 MB"
// N("ordinal", 1) // "1st"
func N(format string, value any) string {
return T("i18n.numeric."+format, value)

View file

@ -134,7 +134,7 @@ func TestN_Good(t *testing.T) {
}{
{"number", "number", int64(1234567), "1,234,567"},
{"percent", "percent", 0.85, "85%"},
{"bytes", "bytes", int64(1536000), "1.5 MB"},
{"bytes", "bytes", int64(1536000), "1.46 MB"},
{"ordinal", "ordinal", 1, "1st"},
}
for _, tt := range tests {

View file

@ -91,7 +91,6 @@ func FormatBytes(bytes int64) string {
GB = MB * 1024
TB = GB * 1024
)
nf := getNumberFormat()
var value float64
var unit string
switch {
@ -110,16 +109,7 @@ func FormatBytes(bytes int64) string {
default:
return core.Sprintf("%d B", bytes)
}
intPart := int64(value)
fracPart := value - float64(intPart)
if fracPart < 0.05 {
return core.Sprintf("%d %s", intPart, unit)
}
fracDigit := int(math.Round(fracPart * 10))
if fracDigit == 10 {
return core.Sprintf("%d %s", intPart+1, unit)
}
return core.Sprintf("%d%s%d %s", intPart, nf.DecimalSep, fracDigit, unit)
return FormatDecimalN(value, 2) + " " + unit
}
// FormatOrdinal formats a number as an ordinal.

View file

@ -100,7 +100,7 @@ func TestFormatBytes(t *testing.T) {
{1024, "1 KB"},
{1536, "1.5 KB"},
{1048576, "1 MB"},
{1536000, "1.5 MB"},
{1536000, "1.46 MB"},
{1073741824, "1 GB"},
{1099511627776, "1 TB"},
}