🎨 Update project structure
This commit is contained in:
16
pkg/internal/i18n/bundle.go
Normal file
16
pkg/internal/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/internal/i18n/embed.go
Normal file
6
pkg/internal/i18n/embed.go
Normal file
@ -0,0 +1,6 @@
|
||||
package i18n
|
||||
|
||||
import "embed"
|
||||
|
||||
//go:embed locale.*.json
|
||||
var FS embed.FS
|
23
pkg/internal/i18n/locale.en.json
Normal file
23
pkg/internal/i18n/locale.en.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"next": "Next",
|
||||
"email": "Email",
|
||||
"username": "Username",
|
||||
"nickname": "Nickname",
|
||||
"password": "Password",
|
||||
"unknown": "Unknown",
|
||||
"apply": "Apply",
|
||||
"back": "Back",
|
||||
"approve": "Approve",
|
||||
"decline": "Decline",
|
||||
"magicToken": "Magic Token",
|
||||
"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!",
|
||||
"signinRequired": "You need to sign in before do that.",
|
||||
"signupTitle": "Sign Up",
|
||||
"signupCaption": "Sign up to create an account on Solarpass, then you can explore the entire Solar Network! Enjoy the next-generation Internet Ecosystem!",
|
||||
"authorizeTitle": "Authorize",
|
||||
"authorizeCaption": "One Solarpass, get entire network.",
|
||||
"mfaTitle": "Multi Factor Authenticate",
|
||||
"mfaCaption": "We need use one more way to verify it is you.",
|
||||
"mfaFactorEmail": "OTP through your email"
|
||||
}
|
23
pkg/internal/i18n/locale.zh.json
Normal file
23
pkg/internal/i18n/locale.zh.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"next": "下一步",
|
||||
"email": "邮件地址",
|
||||
"username": "用户名",
|
||||
"nickname": "昵称",
|
||||
"password": "密码",
|
||||
"unknown": "未知",
|
||||
"apply": "应用",
|
||||
"back": "返回",
|
||||
"approve": "接受",
|
||||
"decline": "拒绝",
|
||||
"magicToken": "魔法令牌",
|
||||
"signinTitle": "登陆",
|
||||
"signinCaption": "登陆 Solarpass 以探索整个 Solar Network,浏览帖子、探索社区、和你的好朋友聊八卦,一切尽在 Solar Network!",
|
||||
"signinRequired": "你需要在那之前登陆",
|
||||
"signupTitle": "注册",
|
||||
"signupCaption": "注册以在 Solarpass 创建一个账号,之后你就可以探索整个 Solar Network,享受下一代互联网生态系统!",
|
||||
"authorizeTitle": "授权",
|
||||
"authorizeCaption": "一个 Solarpass,整个网络。",
|
||||
"mfaTitle": "多因素验证",
|
||||
"mfaCaption": "我们需要另一个方法来确认你是你。",
|
||||
"mfaFactorEmail": "电子邮寄一次性验证码"
|
||||
}
|
15
pkg/internal/i18n/middleware.go
Normal file
15
pkg/internal/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