replace zxq.co/ripple/hanayo
This commit is contained in:
23
localisation.go
Normal file
23
localisation.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/osuYozora/hanayo/modules/locale"
|
||||
)
|
||||
|
||||
// T translates a string into the language specified by the request.
|
||||
func T(c *gin.Context, s string, args ...interface{}) string {
|
||||
return locale.Get(getLang(c), s, args...)
|
||||
}
|
||||
|
||||
func (b *baseTemplateData) T(s string, args ...interface{}) string {
|
||||
return T(b.Gin, s, args...)
|
||||
}
|
||||
|
||||
func getLang(c *gin.Context) []string {
|
||||
s, _ := c.Cookie("language")
|
||||
if s != "" {
|
||||
return []string{s}
|
||||
}
|
||||
return locale.ParseHeader(c.Request.Header.Get("Accept-Language"))
|
||||
}
|
Reference in New Issue
Block a user