-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
45 lines (36 loc) · 1.01 KB
/
main.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
package main
import (
"fmt"
"golang.org/x/text/language"
"github.com/vorlif/spreak"
"github.com/vorlif/spreak/localize"
)
func main() {
bundle, err := spreak.NewBundle(
spreak.WithSourceLanguage(language.English),
spreak.WithDefaultDomain("helloworld"),
spreak.WithDomainPath("helloworld", "../locale"),
spreak.WithRequiredLanguage(language.Spanish),
spreak.WithLanguage(language.German, language.French),
)
if err != nil {
panic(err)
}
t := spreak.NewLocalizer(bundle, language.Spanish)
// TRANSLATORS: This comment is automatically extracted by xspreak
// and can be used to leave useful hints for the translators.
fmt.Println(t.Get("Hello world"))
fmt.Println(t.Localize(GetPlanet()))
t = spreak.NewLocalizer(bundle, language.English)
fmt.Println(t.Get("Hello world"))
// Output:
// Hola Mundo
// No conozco ningún planeta
// Hello world
}
func GetPlanet() *localize.Message {
return &localize.Message{
Singular: "I do not know any planet",
Plural: "I do not know any planets",
}
}