♻️ Refactor frontend
This commit is contained in:
16
pkg/i18n/bundle.go
Normal file
16
pkg/i18n/bundle.go
Normal file
@ -0,0 +1,16 @@
|
||||
package i18n
|
||||
|
||||
import (
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
"golang.org/x/text/language"
|
||||
)
|
||||
|
||||
var Bundle *i18n.Bundle
|
||||
|
||||
func InitInternationalization() {
|
||||
Bundle = i18n.NewBundle(language.English)
|
||||
Bundle.RegisterUnmarshalFunc("json", jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal)
|
||||
Bundle.LoadMessageFileFS(FS, "locale.en.json")
|
||||
Bundle.LoadMessageFileFS(FS, "locale.zh.json")
|
||||
}
|
6
pkg/i18n/embed.go
Normal file
6
pkg/i18n/embed.go
Normal file
@ -0,0 +1,6 @@
|
||||
package i18n
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed locale.*.json
|
||||
var FS embed.FS
|
7
pkg/i18n/locale.en.json
Normal file
7
pkg/i18n/locale.en.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"next": "Next",
|
||||
"username": "Username",
|
||||
"password": "Password",
|
||||
"signinTitle": "Sign In",
|
||||
"signinCaption": "Sign in to Solarpass to explore entire Solar Network. Explore posts, discover communities, talk with your best friends. All these things in the Solar Network!"
|
||||
}
|
7
pkg/i18n/locale.zh.json
Normal file
7
pkg/i18n/locale.zh.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"next": "下一步",
|
||||
"username": "用户名",
|
||||
"password": "密码",
|
||||
"signinTitle": "登陆",
|
||||
"signinCaption": "登陆 Solarpass 以探索整个 Solar Network,浏览帖子、探索社区、和你的好朋友聊八卦,一切尽在 Solar Network!"
|
||||
}
|
15
pkg/i18n/middleware.go
Normal file
15
pkg/i18n/middleware.go
Normal file
@ -0,0 +1,15 @@
|
||||
package i18n
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
||||
)
|
||||
|
||||
func I18nMiddleware(c *fiber.Ctx) error {
|
||||
accept := c.Get(fiber.HeaderAcceptLanguage)
|
||||
localizer := i18n.NewLocalizer(Bundle, accept)
|
||||
|
||||
c.Locals("localizer", localizer)
|
||||
|
||||
return c.Next()
|
||||
}
|
Reference in New Issue
Block a user