gin-blog/internal/middleware/translations.go

23 lines
356 B
Go

package middleware
import (
"blog/global"
"github.com/gin-gonic/gin"
)
func Translations() gin.HandlerFunc {
return func(c *gin.Context) {
locale := c.GetHeader("locale")
switch locale {
case "zh":
c.Set("trans", global.ZhTrans)
case "en":
c.Set("trans", global.EnTrans)
default:
c.Set("trans", global.ZhTrans)
}
c.Next()
}
}