From 26d2799bc3ccc5fb556ac68d7a0bb6aabe69569f Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 30 Dec 2025 21:00:00 +0100 Subject: Simple use cases --- ki18n/ki18n_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 ki18n/ki18n_test.go (limited to 'ki18n/ki18n_test.go') diff --git a/ki18n/ki18n_test.go b/ki18n/ki18n_test.go new file mode 100644 index 0000000..fc134fa --- /dev/null +++ b/ki18n/ki18n_test.go @@ -0,0 +1,38 @@ +package ki18n + +import ( + "bytes" + "context" + "testing" + "testing/fstest" + + "github.com/stretchr/testify/assert" +) + +func TestSimpleText(t *testing.T) { + fs := fstest.MapFS{ + "fr-FR/index.yml": &fstest.MapFile{ + Data: []byte("\"Hello you\": \"Bonjour toi\""), + }, + } + Init(fs) + c := Tr("fr-FR", "Hello you") + w := &bytes.Buffer{} + err := c.Render(context.Background(), w) + assert.NoError(t, err) + assert.Equal(t, "Bonjour toi", w.String()) +} + +func TestVariables(t *testing.T) { + fs := fstest.MapFS{ + "fr-FR/index.yml": &fstest.MapFile{ + Data: []byte("\"Hello %s\": \"Bonjour %s\""), + }, + } + Init(fs) + c := Tr("fr-FR", "Hello %s", "John") + w := &bytes.Buffer{} + err := c.Render(context.Background(), w) + assert.NoError(t, err) + assert.Equal(t, "Bonjour John", w.String()) +} -- cgit v1.3