refactor(i18n): add service option stringers
Some checks failed
Security Scan / security (push) Successful in 14s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 14:33:27 +00:00
parent 0c26ef0caa
commit 0cea872363
2 changed files with 57 additions and 0 deletions

View file

@ -53,6 +53,36 @@ type FSSource struct {
Dir string
}
// String returns a compact summary of the filesystem source.
func (s FSSource) String() string {
if s.Dir == "" {
return core.Sprintf("FSSource{fs=%T}", s.FS)
}
return core.Sprintf("FSSource{fs=%T dir=%q}", s.FS, s.Dir)
}
// String returns a compact summary of the service options.
func (o ServiceOptions) String() string {
extraFS := "[]"
if len(o.ExtraFS) > 0 {
parts := make([]string, len(o.ExtraFS))
for i, src := range o.ExtraFS {
parts[i] = src.String()
}
extraFS = "[" + core.Join(", ", parts...) + "]"
}
return core.Sprintf(
"ServiceOptions{language=%q fallback=%q formality=%s location=%q mode=%s debug=%t extraFS=%s}",
o.Language,
o.Fallback,
o.Formality,
o.Location,
o.Mode,
o.Debug,
extraFS,
)
}
// NewCoreService creates an i18n Core service factory.
// Automatically loads locale filesystems from:
// 1. Embedded go-i18n base translations (grammar, verbs, nouns)

View file

@ -2,6 +2,7 @@ package i18n
import (
"testing"
"testing/fstest"
"dappco.re/go/core"
"github.com/stretchr/testify/assert"
@ -75,3 +76,29 @@ func TestCoreServiceMissingKeysReturnsCopies(t *testing.T) {
require.Len(t, again, 1)
assert.Equal(t, "bar", again[0].Args["foo"])
}
func TestServiceOptionsAndFSSourceString(t *testing.T) {
opts := ServiceOptions{
Language: "en-GB",
Fallback: "en",
Formality: FormalityFormal,
Location: "workspace",
Mode: ModeCollect,
Debug: true,
ExtraFS: []FSSource{
{FS: fstest.MapFS{}, Dir: "locales"},
},
}
got := opts.String()
assert.Contains(t, got, `language="en-GB"`)
assert.Contains(t, got, `fallback="en"`)
assert.Contains(t, got, `formality=formal`)
assert.Contains(t, got, `location="workspace"`)
assert.Contains(t, got, `mode=collect`)
assert.Contains(t, got, `debug=true`)
assert.Contains(t, got, `FSSource{fs=fstest.MapFS dir="locales"}`)
src := FSSource{FS: fstest.MapFS{}, Dir: "translations"}
assert.Equal(t, `FSSource{fs=fstest.MapFS dir="translations"}`, src.String())
}