Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/itpey/echoi18n

Echo framework i18n Middleware.
https://github.com/itpey/echoi18n

echo echo-framework echo-middleware fiber fiber-framework go go-echo go-lang go-lib go-library go-microservice golang i10n i18n i18n-tool i18next-backend localization localization-tool microframework microservices

Last synced: 1 day ago
JSON representation

Echo framework i18n Middleware.

Awesome Lists containing this project

README

        

[//]: # "Title: echoi18n"
[//]: # "Author: itpey"
[//]: # "Attendees: itpey"
[//]: # "Tags: #itpey #go #echo #i18n #go-lang #http #api #https #echo-i18n #echoi18n #middleware"


Echo i18n Middleware


Echo i18n Middleware is a middleware package for the Echo web framework that provides internationalization (i18n) support.



itpey i18n echo middleware Go Reference


itpey i18n echo middleware license

# Features

- Seamless integration with Echo web framework.
- Support for loading message bundles in various formats such as YAML.
- Flexible language negotiation using HTTP Accept-Language header or query parameter.
- Panic-free message localization with error handling.

# Installation

```bash
go get github.com/itpey/echoi18n
```

# Usage

```go
package main

import (
"net/http"

"github.com/itpey/echoi18n"
"github.com/labstack/echo/v4"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)

func main() {
e := echo.New()
e.Use(
echoi18n.NewMiddleware(&echoi18n.Config{
RootPath: "./localize",
AcceptLanguages: []language.Tag{language.Chinese, language.English},
DefaultLanguage: language.Chinese,
}),
)
e.GET("/", func(c echo.Context) error {
localize, err := echoi18n.Localize(c, "welcome")
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, err.Error())
}
return c.String(http.StatusOK, localize)
})
e.GET("/:name", func(c echo.Context) error {
return c.String(http.StatusOK, echoi18n.MustLocalize(c, &i18n.LocalizeConfig{
MessageID: "welcomeWithName",
TemplateData: map[string]string{
"name": c.QueryParam("name"),
},
}))
})
e.Logger.Fatal(e.Start(":1323"))
}
```

# Feedback and Contributions

If you encounter any issues or have suggestions for improvement, please [open an issue](https://github.com/itpey/echoi18n/issues) on GitHub.

We welcome contributions! Fork the repository, make your changes, and submit a pull request.

# License

echoi18n is open-source software released under the MIT License. You can find a copy of the license in the [LICENSE](https://github.com/itpey/echoi18n/blob/main/LICENSE) file.

# Author

echoi18n was created by [itpey](https://github.com/itpey)