Skip to main content
Version: fiberi18n_v2.x.x


Release Discord Test Security Linter

go-i18n support for Fiber.

Note: Requires Go 1.18 and above


This middleware supports Fiber v2.

go get -u
go get -u


NewNew(config ...*fiberi18n.Config) fiber.HandlerCreate a new fiberi18n middleware handler
LocalizeLocalize(ctx *fiber.Ctx, params interface{}) (string, error)Localize returns a localized message. param is one of these type: messageID, *i18n.LocalizeConfig
MustLocalizeMustLocalize(ctx *fiber.Ctx, params interface{}) stringMustLocalize is similar to Localize, except it panics if an error happens. param is one of these type: messageID, *i18n.LocalizeConfig


Nextfunc(c *fiber.Ctx) boolA function to skip this middleware when returned true.nil
RootPathstringThe i18n template folder path."./example/localize"
AcceptLanguages[]language.TagA collection of languages that can be processed.[]language.Tag{language.Chinese, language.English}
FormatBundleFilestringThe type of the template file."yaml"
DefaultLanguagelanguage.TagThe default returned language type.language.English
LoaderLoaderThe implementation of the Loader interface, which defines how to read the file. We provide both os.ReadFile and embed.FS.ReadFile.LoaderFunc(os.ReadFile)
UnmarshalFunci18n.UnmarshalFuncThe function used for decoding template files.yaml.Unmarshal
LangHandlerfunc(ctx *fiber.Ctx, defaultLang string) stringUsed to get the kind of language handled by *fiber.Ctx and defaultLang.Retrieved from the request header Accept-Language or query parameter lang.


package main

import (


func main() {
app := fiber.New()
RootPath: "./example/localize",
AcceptLanguages: []language.Tag{language.Chinese, language.English},
DefaultLanguage: language.Chinese,
app.Get("/", func(c *fiber.Ctx) error {
localize, err := fiberi18n.Localize(c, "welcome")
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
return c.SendString(localize)
app.Get("/:name", func(ctx *fiber.Ctx) error {
return ctx.SendString(fiberi18n.MustLocalize(ctx, &i18n.LocalizeConfig{
MessageID: "welcomeWithName",
TemplateData: map[string]string{
"name": ctx.Params("name"),