Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Errlog ¶
type Errlog func(f string, data ...interface{})
Errlog is an interface that one can embed to catch strings that is not translated. It could be helpful if you want to be notified about missing translations.
type T ¶
type T struct {
// contains filtered or unexported fields
}
T is the instance of a particular translation
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator struct
func New ¶
func New(langs ...*Language) *Translator
New returns a new translator with given languages
Example ¶
package main import ( "bytes" "fmt" translate "github.com/jzs/translate-i18-go" ) func main() { file := `# English file title: zero: No world one: One world many: Many worlds other: Other world apple.count: zero: No apples one: 1 apple few: "{{.Count}} apples" many: "Many apples" other: "{{.Fart}} other apples" ` // Create a new translator with loaded languages and translate. enstream := bytes.NewReader([]byte(file)) en, err := translate.LoadYaml(enstream, "en-us") if err != nil { panic(err) } ts := translate.New(en) fun := ts.Tfunc("en-us") fmt.Println(fun("title")) fmt.Println(fun("apple.count").Plural(0, 10)) // Zero fmt.Println(fun("apple.count").Plural(1, 10)) // One fmt.Println(fun("apple.count").Plural(5, 10)) // Few fmt.Println(fun("apple.count").Plural(11, 10)) // Many data := map[string]string{"Fart": "some"} fmt.Println(fun("apple.count").With(data).Other()) // Other }
Output:
func (*Translator) SetLog ¶
func (t *Translator) SetLog(log Errlog)
SetLog sets a logger on the translator for catching strings where a key or a plurality is missing
Click to show internal directories.
Click to hide internal directories.