Add multi language support for authentication middleware
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
package login
|
||||
|
||||
import (
|
||||
. "ersteller-lib"
|
||||
|
||||
. "maragu.dev/gomponents"
|
||||
. "maragu.dev/gomponents/html"
|
||||
)
|
||||
|
||||
const LoginPath = "/login"
|
||||
const LoginPathDe = "/anmelden"
|
||||
|
||||
var loginTexts *LoginTexts
|
||||
|
||||
type LoginTexts struct {
|
||||
PageTitle I18nText
|
||||
PageDescription I18nText
|
||||
HeroTitle I18nText
|
||||
HeroDescription I18nText
|
||||
GoogleLoginBtn I18nText
|
||||
}
|
||||
|
||||
type Page struct {
|
||||
createPage CreateHtmxPageFunc
|
||||
ViewRoute HtmxRoute
|
||||
}
|
||||
|
||||
func NewPage(createPage CreateHtmxPageFunc, server HtmxServer, path *ActivePath) *Page {
|
||||
if loginTexts == nil {
|
||||
createLoginTexts()
|
||||
}
|
||||
page := &Page{
|
||||
createPage: createPage,
|
||||
}
|
||||
page.ViewRoute = NewHtmxGetRoute(page.View, LanguagePaths{
|
||||
En: LoginPath,
|
||||
De: LoginPathDe,
|
||||
}).SetActivePath(path)
|
||||
page.ViewRoute.Add(server)
|
||||
return page
|
||||
}
|
||||
|
||||
func createLoginTexts() {
|
||||
loginTexts = &LoginTexts{
|
||||
PageTitle: NewI18nText(map[Language]string{
|
||||
En: "Login",
|
||||
De: "Anmelden",
|
||||
}),
|
||||
PageDescription: NewI18nText(map[Language]string{
|
||||
En: "Sign in to your account",
|
||||
De: "Melden Sie sich bei Ihrem Konto an",
|
||||
}),
|
||||
HeroTitle: NewI18nText(map[Language]string{
|
||||
En: "Sign In",
|
||||
De: "Anmelden",
|
||||
}),
|
||||
HeroDescription: NewI18nText(map[Language]string{
|
||||
En: "Please sign in to access your account.",
|
||||
De: "Bitte melden Sie sich an, um auf Ihr Konto zuzugreifen.",
|
||||
}),
|
||||
GoogleLoginBtn: NewI18nText(map[Language]string{
|
||||
En: "Sign in with Google",
|
||||
De: "Mit Google anmelden",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Page) getMetaData() PageWebsiteMetaData {
|
||||
return PageWebsiteMetaData{
|
||||
Title: loginTexts.PageTitle,
|
||||
Lang: En,
|
||||
Description: loginTexts.PageDescription,
|
||||
HideNavigation: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Page) View(c HtmxContext) {
|
||||
content := LoginContent(c.GetLanguage())
|
||||
p.createPage(c, p.getMetaData(), content)
|
||||
}
|
||||
|
||||
func LoginContent(language Language) Group {
|
||||
return []Node{
|
||||
Div(Class("hero-section login-section"),
|
||||
H1(Class("hero-title"), Text(loginTexts.HeroTitle.FromLang(language))),
|
||||
P(Class("hero-description"), Text(loginTexts.HeroDescription.FromLang(language))),
|
||||
Div(Class("login-buttons"),
|
||||
A(
|
||||
Href("/login/google"),
|
||||
Button(
|
||||
Class("btn btn-primary google-login-btn"),
|
||||
Type("button"),
|
||||
Text(loginTexts.GoogleLoginBtn.FromLang(language)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user