forked from gosexy/gettext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgettext_test.go
130 lines (81 loc) · 2.23 KB
/
gettext_test.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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)
fmt.Println(t3)
if t3 != "3 manzanas" {
t.Errorf("Failed translation.")
}
t4 := Gettext("Good morning")
fmt.Println(t4)
if t4 != "Buenos días" {
t.Errorf("Failed translation.")
}
t5 := Gettext("Good bye!")
fmt.Println(t5)
if t5 != "¡Hasta luego!" {
t.Errorf("Failed translation.")
}
}
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.")
}
t3 := Sprintf(NGettext("An apple", "%d apples", 3), 3)
fmt.Println(t3)
if t3 != "3 Äpfel" {
t.Errorf("Failed translation.")
}
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.")
}
}