add i18n support

This commit is contained in:
landaiqing
2024-11-12 22:59:39 +08:00
parent 97ca3fc7b0
commit ae743ba8a6
62 changed files with 4468 additions and 2797 deletions

14
common/i18n/parse.go Normal file
View File

@@ -0,0 +1,14 @@
package i18n
import "golang.org/x/text/language"
func MatchCurrentLanguageTag(accept string, supportTags []language.Tag) language.Tag {
langTags, _, err := language.ParseAcceptLanguage(accept)
if err != nil {
langTags = []language.Tag{language.English}
}
var matcher = language.NewMatcher(supportTags)
_, i, _ := matcher.Match(langTags...)
tag := supportTags[i]
return tag
}