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 63 64 65 66 67
|
package gettext
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
const (
spanishMexico = "es_MX.utf8"
deutschDeutschland = "de_DE.utf8"
frenchFrance = "fr_FR.utf8"
)
// a setUp would be nice
func init() {
textDomain := "example"
BindTextdomain(textDomain, "_examples/")
Textdomain(textDomain)
}
func TestSpanish(t *testing.T) {
os.Setenv("LANGUAGE", spanishMexico)
SetLocale(LcAll, "")
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) {
os.Setenv("LANGUAGE", deutschDeutschland)
SetLocale(LcAll, "")
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.
os.Setenv("LANGUAGE", frenchFrance)
SetLocale(LcAll, "")
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!"))
}
|