gin-blog/internal/middleware/translations.go

23 lines
356 B
Go
Raw Permalink Normal View History

2021-05-28 10:40:39 +00:00
package middleware
import (
"blog/global"
2021-05-28 10:40:39 +00:00
"github.com/gin-gonic/gin"
)
func Translations() gin.HandlerFunc {
return func(c *gin.Context) {
2021-05-28 10:40:39 +00:00
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)
2021-05-28 10:40:39 +00:00
}
c.Next()
}
}