2021-05-28 10:40:39 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
2021-06-03 09:03:43 +00:00
|
|
|
"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-06-03 09:03:43 +00:00
|
|
|
|
2021-05-28 10:40:39 +00:00
|
|
|
locale := c.GetHeader("locale")
|
2021-06-03 09:03:43 +00:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
}
|