Documentation ¶
Overview ¶
Package i18n i18n 国际化
example: bundle := i18n.NewBundle(language.Chinese).LoadFiles("./locales", toml.Unmarshal) log.Println(bundle.NewPrinter(language.English).Translate("Hello", i18n.Data{"name": "medivh", "count": 156}, 156)) # return 你好世界
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var LangKey = "lang"
LangKey 默认从URL取语言值得键名
Functions ¶
Types ¶
type Bundle ¶
type Bundle struct {
// contains filtered or unexported fields
}
Bundle 国际化对外操作结构体
func (*Bundle) LoadFiles ¶
LoadFiles walk file dir and load messages language file like
- path | -- zh.yaml | -- en.yaml
func (*Bundle) NewPrinter ¶
NewPrinter 根据传入语言tag获得具体翻译组件
type Message ¶
type Message struct { ID string // message key Default *template.Template // message template Zero *template.Template // message template One *template.Template // message template Two *template.Template // message template Few *template.Template // message template Many *template.Template // message template }
Message 具体翻译模板的内容
type Printer ¶
type Printer struct {
// contains filtered or unexported fields
}
Printer 一个新的message translate 对象, 一般不需要调用他
func (*Printer) SetFewRule ¶
SetFewRule 自定义 few 信息模板的few规则, 在min-max范围内将使用few模板
func (*Printer) SetManyRule ¶
SetManyRule 自定义 Many信息模板规则,大于等于 min 将使用 many 模板
Click to show internal directories.
Click to hide internal directories.