/
c_home.go
46 lines (38 loc) · 1001 Bytes
/
c_home.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package auth
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
"github.com/kapmahc/lotus/web"
"golang.org/x/text/language"
)
func (p *Engine) getLocales(c *gin.Context) (interface{}, error) {
lang, err := language.Parse(c.Param("lang"))
if err != nil {
return nil, err
}
return p.I18n.Locales(lang.String()), nil
}
func (p *Engine) getLayout(c *gin.Context) {
lang := c.MustGet(web.LOCALE).(string)
ret := gin.H{}
for _, k := range []string{"title", "subTitle", "keywords", "description", "copyright"} {
ret[k] = p.I18n.T(lang, fmt.Sprintf("site.%s", k))
}
author := gin.H{}
for _, k := range []string{"email", "name"} {
var v string
p.Dao.Get(fmt.Sprintf("site.author.%s", k), &v)
author[k] = v
}
ret["author"] = author
links := gin.H{}
for _, k := range []string{"top", "bottom"} {
var v []web.Link
p.Dao.Get(fmt.Sprintf("site.links.%s", k), &v)
links[k] = v
}
ret["links"] = links
ret["languages"] = p.I18n.Languages()
c.JSON(http.StatusOK, ret)
}