mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
1.4 KiB
1.4 KiB
gettext-go
PkgDoc: http://godoc.org/github.com/chai2010/gettext-go/gettext
Install
go get github.com/chai2010/gettext-go/gettext
go run hello.go
The godoc.org or gowalker.org has more information.
Example
package main
import (
"fmt"
"github.com/chai2010/gettext-go/gettext"
)
func main() {
gettext.SetLocale("zh_CN")
gettext.Textdomain("hello")
gettext.BindTextdomain("hello", "local", nil)
// gettext.BindTextdomain("hello", "local", nil) // from local dir
// gettext.BindTextdomain("hello", "local.zip", nil) // from local zip file
// gettext.BindTextdomain("hello", "local.zip", zipData) // from embedded zip data
// translate source text
fmt.Println(gettext.Gettext("Hello, world!"))
// Output: 你好, 世界!
// if no msgctxt in PO file (only msgid and msgstr),
// specify context as "" by
fmt.Println(gettext.PGettext("", "Hello, world!"))
// Output: 你好, 世界!
// translate resource
fmt.Println(string(gettext.Getdata("poems.txt"))))
// Output: ...
}
Go file: hello.go; PO file: hello.po;
BUGS
Please report bugs to chaishushan@gmail.com.
Thanks!