aboutsummaryrefslogtreecommitdiff
path: root/gettext_test.go
diff options
context:
space:
mode:
authorJosé Carlos <jose.carlos@menteslibres.net>2016-02-20 07:33:14 -0600
committerJosé Carlos <jose.carlos@menteslibres.net>2016-02-20 07:33:14 -0600
commitea584c8c09c390260b68a9e1a15d60f7ffe480c5 (patch)
treed84ea7ec068b7998adae2bd4580db9dc78584c56 /gettext_test.go
parentMerge branch 'master' of github.com:gosexy/gettext (diff)
parentCode cleaning. (diff)
downloadgotext-ea584c8c09c390260b68a9e1a15d60f7ffe480c5.tar.gz
gotext-ea584c8c09c390260b68a9e1a15d60f7ffe480c5.tar.xz
Merge pull request #9 from gosexy/issue-5
Code cleaning.
Diffstat (limited to 'gettext_test.go')
-rw-r--r--gettext_test.go165
1 files changed, 32 insertions, 133 deletions
diff --git a/gettext_test.go b/gettext_test.go
index 8e88180..6c58ab3 100644
--- a/gettext_test.go
+++ b/gettext_test.go
@@ -1,163 +1,62 @@
package gettext
import (
- "fmt"
- "os"
"testing"
-)
-
-/*
- NOTE:
-
- xgettext does not officially support Go syntax, however, you can generate a valid .pot file by forcing
- xgettest to use the C++ syntax:
-
- % xgettext -d example -s gettext_test.go -o example.pot -L c++ -i --keyword=NGettext:1,2 --keyword=Gettext
-
- This will generate a example.pot file.
-
- After translating the .pot file, you must generate .po and .mo files.
-
- Remember to set the UTF-8 charset.
-
- % msginit -l es_MX -o example.po -i example.pot
- % msgfmt -c -v -o example.mo example.po
-
- And finally, move the .mo file to an appropriate location.
-
- % mv example.mo examples/es_MX.utf8/LC_MESSAGES/example.mo
-
-*/
-
-func TestSpanishMexico(t *testing.T) {
-
- os.Setenv("LANGUAGE", "es_MX.utf8")
-
- SetLocale(LC_ALL, "")
- BindTextdomain("example", "./examples/")
- Textdomain("example")
-
- t1 := Gettext("Hello, world!")
-
- fmt.Println(t1)
-
- if t1 != "¡Hola mundo!" {
- t.Errorf("Failed translation.")
- }
-
- t2 := Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage")
-
- fmt.Println(t2)
-
- if t2 != "Una manzana" {
- t.Errorf("Failed translation.")
- }
- t3 := Sprintf(NGettext("An apple", "%d apples", 3), 3)
+ "github.com/stretchr/testify/assert"
+)
- fmt.Println(t3)
+const (
+ spanishMexico = "es_MX.utf8"
+ deutschDeutschland = "de_DE.utf8"
+ frenchFrance = "fr_FR.utf8"
+)
- if t3 != "3 manzanas" {
- t.Errorf("Failed translation.")
- }
+func TestSpanish(t *testing.T) {
+ SetLocale(LcAll, spanishMexico)
- t4 := Gettext("Good morning")
+ textDomain := "example"
- fmt.Println(t4)
+ BindTextdomain(textDomain, "_examples/")
+ Textdomain(textDomain)
- if t4 != "Buenos días" {
- t.Errorf("Failed translation.")
- }
+ assert.Equal(t, "¡Hola mundo!", Gettext("Hello, world!"))
- t5 := Gettext("Good bye!")
+ assert.Equal(t, "Una manzana", Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage"))
- fmt.Println(t5)
+ assert.Equal(t, "3 manzanas", Sprintf(NGettext("An apple", "%d apples", 3), 3))
- if t5 != "¡Hasta luego!" {
- t.Errorf("Failed translation.")
- }
+ assert.Equal(t, "Buenos días", Gettext("Good morning"))
+ assert.Equal(t, "¡Hasta luego!", Gettext("Good bye!"))
}
-func TestGermanDeutschland(t *testing.T) {
-
- os.Setenv("LANGUAGE", "de_DE.utf8")
-
- SetLocale(LC_ALL, "")
- BindTextdomain("example", "./examples/")
- Textdomain("example")
-
- t1 := Gettext("Hello, world!")
-
- fmt.Println(t1)
-
- if t1 != "Hallo, Welt!" {
- t.Errorf("Failed translation.")
- }
-
- t2 := Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage")
-
- fmt.Println(t2)
-
- if t2 != "Ein Apfel" {
- t.Errorf("Failed translation.")
- }
+func TestDeutsch(t *testing.T) {
+ SetLocale(LcAll, deutschDeutschland)
- t3 := Sprintf(NGettext("An apple", "%d apples", 3), 3)
+ assert.Equal(t, "Hallo, Welt!", Gettext("Hello, world!"))
- fmt.Println(t3)
+ assert.Equal(t, "Ein Apfel", Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage"))
- if t3 != "3 Äpfel" {
- t.Errorf("Failed translation.")
- }
+ assert.Equal(t, "3 Äpfel", Sprintf(NGettext("An apple", "%d apples", 3), 3))
- t4 := Gettext("Good morning")
-
- fmt.Println(t4)
-
- if t4 != "Guten morgen" {
- t.Errorf("Failed translation.")
- }
-
- t5 := Gettext("Good bye!")
-
- fmt.Println(t5)
-
- if t5 != "Aufwiedersehen!" {
- t.Errorf("Failed translation.")
- }
+ assert.Equal(t, "Guten morgen", Gettext("Good morning"))
+ assert.Equal(t, "Auf Wiedersehen!", Gettext("Good bye!"))
}
-func TestDGettextFallback(t *testing.T) {
- os.Setenv("LANGUAGE", "de_DE.utf8")
-
- SetLocale(LC_ALL, "")
- BindTextdomain("example", "./examples/")
- Textdomain("example")
-
- t1 := DGettext("", "Hello, world!")
-
- fmt.Println(t1)
-
- if t1 != "Hallo, Welt!" {
- t.Errorf("Failed translation fallback.")
- }
-
- t2 := Sprintf(DNGettext("", "An apple", "%d apples", 1), 1, "garbage")
+func TestFrench(t *testing.T) {
+ // Note that we don't have a french translation.
- fmt.Println(t2)
+ SetLocale(LcAll, frenchFrance)
- if t2 != "Ein Apfel" {
- t.Errorf("Failed translation fallback.")
- }
+ assert.Equal(t, "Hello, world!", Gettext("Hello, world!"))
- t3 := Sprintf(DNGettext("", "An apple", "%d apples", 3), 3)
+ assert.Equal(t, "An apple", Sprintf(NGettext("An apple", "%d apples", 1), 1, "garbage"))
- fmt.Println(t3)
+ assert.Equal(t, "3 apples", Sprintf(NGettext("An apple", "%d apples", 3), 3))
- if t3 != "3 Äpfel" {
- t.Errorf("Failed translation fallback.")
- }
+ assert.Equal(t, "Good morning", Gettext("Good morning"))
+ assert.Equal(t, "Good bye!", Gettext("Good bye!"))
}