Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/itpey/echoi18n
- Owner: itpey
- License: mit
- Created: 2024-06-02T19:57:43.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-06-02T22:11:28.000Z (6 months ago)
- Last Synced: 2024-06-03T04:28:44.787Z (6 months ago)
- Topics: 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
- Language: Go
- Homepage: https://github.com/itpey/echoi18n
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.# 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 mainimport (
"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)