Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
John Guo
2022-10-14 10:10:27 +08:00
committed by GitHub
parent e756f284be
commit 2598745e50
14 changed files with 195 additions and 64 deletions

View File

@ -0,0 +1,9 @@
gfcli:
build:
name: "pack"
arch: "amd64"
system: "darwin"
packSrc: "resource/public,manifest/i18n"
packDst: "packed/build_packed_data.go"
mod: ""
cgo: 0

28
example/pack/main.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
_ "github.com/gogf/gf/example/pack/packed"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/i18n/gi18n"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gres"
)
func main() {
gres.Dump()
s := g.Server()
s.SetPort(8199)
s.SetServerRoot("resource/public")
s.BindHandler("/i18n", func(r *ghttp.Request) {
var (
lang = r.Get("lang", "zh-CN").String()
ctx = gi18n.WithLanguage(r.Context(), lang)
content string
)
content = g.I18n().T(ctx, `{#hello} {#world}!`)
r.Response.Write(content)
})
s.Run()
}

View File

@ -0,0 +1,2 @@
hello: "こんにちは"
world: "世界"

View File

@ -0,0 +1,2 @@
hello: "Привет"
world: "мир"

View File

@ -0,0 +1,2 @@
hello: "你好"
world: "世界"

View File

@ -0,0 +1 @@
package packed

View File

@ -0,0 +1,8 @@
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>