aboutsummaryrefslogtreecommitdiff
path: root/gettext_test.go
blob: 6c58ab33d1f6762204ab73cb23e22d4b84790570 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gettext

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

const (
	spanishMexico      = "es_MX.utf8"
	deutschDeutschland = "de_DE.utf8"
	frenchFrance       = "fr_FR.utf8"
)

func TestSpanish(t *testing.T) {
	SetLocale(LcAll, spanishMexico)

	textDomain := "example"

	BindTextdomain(textDomain, "_examples/")
	Textdomain(textDomain)

	assert.Equal(t, "¡Hola mundo!", Gettext("Hello, world!"))

	assert.Equal(t, "Una manzana", Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage"))

	assert.Equal(t, "3 manzanas", Sprintf(NGettext("An apple", "%d apples", 3), 3))

	assert.Equal(t, "Buenos días", Gettext("Good morning"))

	assert.Equal(t, "¡Hasta luego!", Gettext("Good bye!"))
}

func TestDeutsch(t *testing.T) {
	SetLocale(LcAll, deutschDeutschland)

	assert.Equal(t, "Hallo, Welt!", Gettext("Hello, world!"))

	assert.Equal(t, "Ein Apfel", Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage"))

	assert.Equal(t, "3 Äpfel", Sprintf(NGettext("An apple", "%d apples", 3), 3))

	assert.Equal(t, "Guten morgen", Gettext("Good morning"))

	assert.Equal(t, "Auf Wiedersehen!", Gettext("Good bye!"))
}

func TestFrench(t *testing.T) {
	// Note that we don't have a french translation.

	SetLocale(LcAll, frenchFrance)

	assert.Equal(t, "Hello, world!", Gettext("Hello, world!"))

	assert.Equal(t, "An apple", Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage"))

	assert.Equal(t, "3 apples", Sprintf(NGettext("An apple", "%d apples", 3), 3))

	assert.Equal(t, "Good morning", Gettext("Good morning"))

	assert.Equal(t, "Good bye!", Gettext("Good bye!"))
}