updated

This commit is contained in:
landaiqing
2024-11-14 01:58:20 +08:00
parent c95d5fc041
commit 3b8e3df27a
83 changed files with 172212 additions and 343 deletions

View File

@@ -1,28 +0,0 @@
package i18n
import (
"net/http"
"golang.org/x/text/language"
)
type I18nMiddleware struct {
supportTags []language.Tag
localizationFiles []string
}
func NewI18nMiddleware(supportTags []language.Tag, localizationFiles []string) *I18nMiddleware {
return &I18nMiddleware{
supportTags: supportTags,
localizationFiles: localizationFiles,
}
}
func (m *I18nMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
lang := r.Header.Get(defaultLangHeaderKey)
langTag := MatchCurrentLanguageTag(lang, m.supportTags)
bundle := NewBundle(langTag, m.localizationFiles...)
next(w, withRequest(r, langTag, bundle))
}
}