aboutsummaryrefslogtreecommitdiff
path: root/ki18n/ki18n_test.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2025-12-30 21:00:00 +0100
committerMartin Kagamino Lehoux <martin@lehoux.net>2025-12-30 21:00:00 +0100
commit26d2799bc3ccc5fb556ac68d7a0bb6aabe69569f (patch)
tree4b64928479dab07d9331a47690cbd1b2c629006d /ki18n/ki18n_test.go
parentcfefc30a5058158671954e8ef92f87484abfaf43 (diff)
Simple use cases
Diffstat (limited to 'ki18n/ki18n_test.go')
-rw-r--r--ki18n/ki18n_test.go38
1 files changed, 38 insertions, 0 deletions
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())
+}