BotText is a Go package that help you:
- Translate your bot into multiple languages,
- Make your bot more interesting by expressing the same thing in different ways.
Make sure you have setup GOPATH
go get github.com/michlabs/bottext
Create a new language file named text.yml
:
vi:
welcome:
- Xin chào %s!
- Hi %s
en:
welcome:
- Hello %s!
- Welcome %s!
- Hi %s
Then in your source code:
package main
import (
"fmt"
"github.com/michlabs/bottext"
)
func main() {
bottext.MustLoad("text.yml")
var T1 bottext.BotTextFunc
T1 = bottext.New("en")
for i := 0; i < 10; i ++ {
fmt.Printf(T1("welcome") + "\n", "Donald Trump")
}
T2 := bottext.New("vi")
for i := 0; i < 10; i ++ {
fmt.Printf(T2("welcome"), "Đỗ Nam Trung")
}
}
Read in Godoc