Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ConfigDefault = &Config{ RootPath: "./example/localize", DefaultLanguage: language.English, AcceptLanguages: []language.Tag{language.Chinese, language.English}, FormatBundleFile: "yaml", UnmarshalFunc: yaml.Unmarshal, Loader: LoaderFunc(os.ReadFile), LangHandler: defaultLangHandler, }
Functions ¶
func GetMessage ¶
GetMessage get the i18n message
param is one of these type: messageID, *i18n.LocalizeConfig Example: GetMessage("hello") // messageID is hello GetMessage(&i18n.LocalizeConfig{ MessageID: "welcomeWithName", TemplateData: map[string]string{ "name": context.Param("name"), }, })
func MustGetMessage ¶
func MustGetMessage(params interface{}) string
MustGetMessage get the i18n message without error handling
param is one of these type: messageID, *i18n.LocalizeConfig Example: MustGetMessage("hello") // messageID is hello MustGetMessage(&i18n.LocalizeConfig{ MessageID: "welcomeWithName", TemplateData: map[string]string{ "name": context.Param("name"), }, })
Types ¶
type Config ¶
type Config struct { // Next defines a function to skip this middleware when returned true. // // Optional. Default: nil Next func(c *fiber.Ctx) bool // RootPath is i18n template folder path // // Default: ./example/localize RootPath string // AcceptLanguages is a collection of languages that can be processed // // Optional. Default: []language.Tag{language.Chinese, language.English} AcceptLanguages []language.Tag // FormatBundleFile is type of template file. // // Optional. Default: "yaml" FormatBundleFile string // DefaultLanguage is the default returned language type // // Optional. Default: language.English DefaultLanguage language.Tag // Loader implements the Loader interface, which defines how to read the file. // We provide both os.ReadFile and embed.FS.ReadFile // Optional. Default: LoaderFunc(os.ReadFile) Loader Loader // UnmarshalFunc for decoding template files // // Optional. Default: yaml.Unmarshal UnmarshalFunc i18n.UnmarshalFunc // LangHandler is used to get the kind of language handled by *fiber.Ctx and defaultLang // // Optional. Default: The language type is retrieved from the request header: `Accept-Language` or query param : `lang` LangHandler func(ctx *fiber.Ctx, defaultLang string) string // contains filtered or unexported fields }
type EmbedLoader ¶
func (*EmbedLoader) LoadMessage ¶
func (e *EmbedLoader) LoadMessage(path string) ([]byte, error)
type LoaderFunc ¶
func (LoaderFunc) LoadMessage ¶
func (f LoaderFunc) LoadMessage(path string) ([]byte, error)
Click to show internal directories.
Click to hide internal directories.