diff --git a/front.go b/front.go index 8ca4665..8ef69b1 100644 --- a/front.go +++ b/front.go @@ -1,6 +1,7 @@ package main import ( + "bytes" "context" "encoding/base64" "encoding/json" @@ -16,6 +17,7 @@ import ( "github.com/zitadel/oidc/v3/pkg/oidc" "golang.org/x/text/language" "gorm.io/gorm" + "html" "html/template" "io" "log" @@ -66,6 +68,8 @@ func NewTemplate(app *App) *Template { } funcMap := template.FuncMap{ + "render": RenderHTML, + "html": func(x string) template.HTML { return template.HTML(x) }, "PrimaryPlayerSkinURL": app.PrimaryPlayerSkinURL, "PlayerSkinURL": app.PlayerSkinURL, "InviteURL": app.InviteURL, @@ -156,7 +160,23 @@ func NewWebError(returnURL string, message string, args ...interface{}) error { } } +func RenderHTML(templateString string, args ...interface{}) (template.HTML, error) { + t, err := template.New("").Parse(templateString) + if err != nil { + return "", err + } + + var buf bytes.Buffer + err = t.Execute(&buf, args) + if err != nil { + return "", err + } + + return template.HTML(buf.String()), nil +} + type baseContext struct { + T func(string, ...interface{}) template.HTML App *App L *gotext.Locale URL string @@ -165,10 +185,28 @@ type baseContext struct { ErrorMessage string } +func NewT(l *gotext.Locale) func(string, ...interface{}) template.HTML { + return func(msgid string, args ...interface{}) template.HTML { + sanitized := make([]interface{}, 0, len(args)) + for _, arg := range args { + switch arg.(type) { + case template.HTML: + sanitized = append(sanitized, arg) + default: + sanitized = append(sanitized, html.EscapeString(fmt.Sprint(arg))) + } + } + return template.HTML(l.Get(msgid, sanitized...)) + } +} + func (app *App) NewBaseContext(c *echo.Context) baseContext { + l := (*c).Get(CONTEXT_KEY_LOCALE).(*gotext.Locale) + T := NewT((*c).Get(CONTEXT_KEY_LOCALE).(*gotext.Locale)) return baseContext{ App: app, - L: (*c).Get(CONTEXT_KEY_LOCALE).(*gotext.Locale), + L: l, + T: T, URL: (*c).Request().URL.RequestURI(), SuccessMessage: app.lastSuccessMessage(c), WarningMessage: app.lastWarningMessage(c), diff --git a/locales/es/default.po b/locales/es/default.po index 4d3ffa4..0986540 100644 --- a/locales/es/default.po +++ b/locales/es/default.po @@ -14,3 +14,99 @@ msgstr "Cuenta de %s" msgid "Log out" msgstr "Cerrar sesión" + +msgid "Log in" +msgstr "Iniciar sesión" + +msgid "Sign in with %s" +msgstr "Iniciar sesión con %s" + +msgid "or" +msgstr "o" + +msgid "Username" +msgstr "Nombre de usuario" + +msgid "Password" +msgstr "Contraseña" + +msgid "Configuring your client" +msgstr "Configurando tu cliente" + +msgid "Using %s on the client requires a third-party launcher that supports custom API servers. %s, a fork of Prism Launcher, is recommended, but %s also works. Both are free/libre." +msgstr "Usar %s en el cliente requiere un lanzador de terceros que soporte servidores API personalizados. Se recomienda %s, un fork de Prism Launcher, pero %s también funciona. Ambos son libres." + +msgid "Click your account in the top right and select “Manage Accounts...”." +msgstr "Haz clic en tu cuenta en la esquina superior derecha y selecciona “Administrar cuentas...”." + +msgid "Click “Add authlib-injector” in the right-hand sidebar." +msgstr "Haz clic en “Add authlib-injector” en la barra lateral derecha." + +msgid "Enter your player name and your %s password or Minecraft Token, and use %s for the URL. Click “OK”." +msgstr "Introduce tu nombre de jugador y tu contraseña de %s o Token de Minecraft, y usa %s para la URL. Haz clic en “Aceptar”." + +msgid "Go to the “Account List” view by clicking the account at the top of the sidebar." +msgstr "Ve a la vista “Lista de cuentas” haciendo clic en la cuenta en la parte superior de la barra lateral." + +msgid "At the bottom left, click “New Auth Server” and enter %s. Click “Next” and then “Finish”." +msgstr "En la parte inferior izquierda, haz clic en “Añadir un servidor de autenticación” e ingresa %s. Haz clic en “Siguiente” y luego en “Finalizar”." + +msgid "In the sidebar, click the newly-added authentication server, labeled “%s”. Enter your %s player name and password and click “Login”." +msgstr "En la barra lateral, haz clic en el servidor de autenticación recién añadido, etiquetado como “%s”. Ingresa tu nombre de jugador y contraseña de %s y haz clic en “Acceder”." + +msgid "Other launchers" +msgstr "Otros lanzadores" + +msgid "Use the authlib-injector URL %s." +msgstr "Usa la URL de authlib-injector %s." + +msgid "Or, if your launcher supports custom API servers but not via authlib-injector, use the following URLs:" +msgstr "O, si tu lanzador soporta servidores API personalizados pero no a través de authlib-injector, usa las siguientes URLs:" + +msgid "Authentication server:" +msgstr "Servidor de “Authentication”:" + +msgid "Account server:" +msgstr "Servidor de “Account”:" + +msgid "Session server:" +msgstr "Servidor de “Session”:" + +msgid "Services server:" +msgstr "Servidor de “Services”:" + +msgid "Configuring your server" +msgstr "Configurando tu servidor" + +msgid "Minecraft 1.16 and later" +msgstr "Minecraft 1.16 y posteriores" + +msgid "On recent versions of Minecraft, you can use %s on an unmodified Vanilla server. To do so, add the following arguments before you specify the jar file when you start the server:" +msgstr "En las versiones recientes de Minecraft, puedes usar %s en un servidor Vanilla sin modificaciones. Para hacerlo, agrega los siguientes argumentos antes de especificar el archivo jar al iniciar el servidor:" + +msgid "For example, the full command you use to start the server might be:" +msgstr "Por ejemplo, el comando completo que usas para iniciar el servidor podría ser:" + +msgid "Minecraft 1.7.2 through 1.15.2" +msgstr "Minecraft 1.7.2 a 1.15.2" + +msgid "Refer to the authlib-injector documentation on setting up a server." +msgstr "Consulta la documentación de authlib-injector sobre cómo configurar un servidor." + +msgid "Alternatively, you can patch your server to use a newer version of Mojang's authlib that supports the arguments for custom API servers. Replace the files under com/mojang/authlib in your server.jar with the files in authlib-1.6.25.jar." +msgstr "Alternativamente, puedes parchear tu servidor para usar una versión más reciente de authlib de Mojang que soporte los argumentos para servidores API personalizados. Reemplaza los archivos bajo com/mojang/authlib en tu server.jar con los archivos en authlib-1.6.25.jar." + +msgid "Late Classic, Alpha, Beta, etc. through Minecraft 1.6.4" +msgstr "Clásico Tardío, Alpha, Beta, etc. hasta Minecraft 1.6.4" + +msgid "Use %s and start the server with the -Dminecraft.api.session.host argument described above. For example, the full command you use to start the server might be:" +msgstr "Usa %s y arranca el servidor con el argumento -Dminecraft.api.session.host descrito arriba. Por ejemplo, el comando completo que usas para iniciar el servidor podría ser:" + +msgid "Drasl version %s." +msgstr "Versión de Drasl %s." + +msgid "Licensed as %s." +msgstr "Con licencia %s." + +msgid "Source code." +msgstr "Código fuente." diff --git a/view/footer.tmpl b/view/footer.tmpl index d702da5..be27c4c 100644 --- a/view/footer.tmpl +++ b/view/footer.tmpl @@ -2,9 +2,9 @@ {{ if .App.Config.EnableFooter }}
- Drasl version {{ .App.Constants.Version }}. Licensed under - {{ .App.Constants.License }}. - Source code here. + {{ call .T `Drasl version %s.` .App.Constants.Version }} + {{ call .T `Licensed as %s.` (render `{{ index . 1 }}` .App.Constants.LicenseURL .App.Constants.License) }} + {{ call .T `Source code.` .App.Constants.RepositoryURL }} {{ end }} {{ end }} diff --git a/view/header.tmpl b/view/header.tmpl index 080ad30..c6aba80 100644 --- a/view/header.tmpl +++ b/view/header.tmpl @@ -11,20 +11,20 @@
{{ if .User }} {{ if .User.IsAdmin }} - {{ .L.Get "Admin" }} + {{ call .T "Admin" }} {{ end }} {{ .L.Get "%s's Account" .User.Username }}{{ call .T "%s's Account" .User.Username }}
- +
{{ else }} - {{ .L.Get "Register" }} + {{ call .T "Register" }} {{ end }}
diff --git a/view/layout.tmpl b/view/layout.tmpl index 6457b73..e8db85f 100644 --- a/view/layout.tmpl +++ b/view/layout.tmpl @@ -1,6 +1,6 @@ {{ define "base" }} - + diff --git a/view/root.tmpl b/view/root.tmpl index df247aa..1130fdb 100644 --- a/view/root.tmpl +++ b/view/root.tmpl @@ -4,7 +4,10 @@ {{ define "content" }} {{ template "header" . }} -

Log in

+ + {{ $authlibInjectorA := render `{{ index . 1}}` .App.AuthlibInjectorURL .App.AuthlibInjectorURL }} + +

{{ call .T "Log in" }}

{{ $dividerNeeded := false }} @@ -16,7 +19,7 @@

{{ range $provider := $.WebOIDCProviders }}

- Sign in with {{ $provider.Name }} + {{ call $.T "Sign in with %s" $provider.Name }}

{{ end }} {{ $dividerNeeded = true }} @@ -24,106 +27,94 @@ {{ if .App.Config.AllowPasswordLogin }} {{ if $dividerNeeded }} -
or
+
{{ call .T "or" }}
{{ $dividerNeeded = false }} {{ end }}
- + - +
{{ $dividerNeeded = true }} {{ end }} -

Configuring your client

+

{{ call .T "Configuring your client" }}

- Using {{ .App.Config.ApplicationName }} on the client requires a third-party launcher that supports - custom API servers. - Fjord Launcher, a - fork of Prism Launcher, is recommended, but - HMCL also works. Both are - free/libre. + {{ call .T "Using %s on the client requires a third-party launcher that supports custom API servers. %s, a fork of Prism Launcher, is recommended, but %s also works. Both are free/libre." + .App.Config.ApplicationName + (html `Fjord Launcher`) + (html `HMCL`) }}

Fjord Launcher

    -
  1. - Click your account in the top right and select "Manage Accounts...". -
  2. -
  3. Click "Add authlib-injector" in the right-hand sidebar.
  4. -
  5. - Enter your player name and your {{ .App.Config.ApplicationName }} password or Minecraft Token, and use - {{ .App.AuthlibInjectorURL }} - for the URL. Click "OK". -
  6. +
  7. {{ call .T "Click your account in the top right and select “Manage Accounts...”." }}
  8. +
  9. {{ call .T "Click “Add authlib-injector” in the right-hand sidebar." }}
  10. +
  11. {{ call .T + "Enter your player name and your %s password or Minecraft Token, and use %s for the URL. Click “OK”." + .App.Config.ApplicationName + $authlibInjectorA + }}

HMCL

    +
  1. {{ call .T "Go to the “Account List” view by clicking the account at the top of the sidebar." }}
  2. - Go to the "Account List" view by clicking the account at the top of the - sidebar. + {{ call .T + "At the bottom left, click “New Auth Server” and enter %s. Click “Next” and then “Finish”." + $authlibInjectorA + }}
  3. - At the bottom left, click "New Auth Server" and enter - {{ .App.AuthlibInjectorURL }}. - Click "Next" and then "Finish". -
  4. -
  5. - In the sidebar, click the newly-added authentication server, labeled - "{{ .App.Config.InstanceName }}". Enter your {{ .App.Config.ApplicationName }} player name and password - and click "Login". + {{ call .T + "In the sidebar, click the newly-added authentication server, labeled “%s”. Enter your %s player name and password and click “Login”." + .App.Config.InstanceName + .App.Config.ApplicationName + }}
-

Other Launchers

+

{{ call .T "Other launchers" }}

-

- Use the authlib-injector URL - {{ .App.AuthlibInjectorURL }}. -

+

{{ call .T "Use the authlib-injector URL %s." $authlibInjectorA }}

-

- Or, if your launcher supports custom API servers but not via - authlib-injector, use the following URLs: -

+

{{ call .T "Or, if your launcher supports custom API servers but not via authlib-injector, use the following URLs:" }}

- + - + - + - +
Authentication Server:{{ call .T "Authentication server:" }} {{ .App.AuthURL }}
Account Server:{{ call .T "Account server:" }} {{ .App.AccountURL }}
Session Server:{{ call .T "Session server:" }} {{ .App.SessionURL }}
Services Server:{{ call .T "Services server:" }} {{ .App.ServicesURL }}
-

Configuring your server

+

{{ call .T "Configuring your server" }}

-

Minecraft 1.16 and later

+

{{ call .T "Minecraft 1.16 and later" }}

- On recent versions of Minecraft, you can use {{ .App.Config.ApplicationName }} on an unmodified Vanilla - server. To do so, add the following arguments before you specify the jar file - when you start the server: +

{{ call .T "On recent versions of Minecraft, you can use %s on an unmodified Vanilla server. To do so, add the following arguments before you specify the jar file when you start the server:" }}

 -Dminecraft.api.env=custom
 -Dminecraft.api.auth.host={{ .App.AuthURL }}
@@ -131,7 +122,7 @@
 -Dminecraft.api.session.host={{ .App.SessionURL }}
 -Dminecraft.api.services.host={{ .App.ServicesURL }}
- For example, the full command you use to start the server might be: +

{{call .T "For example, the full command you use to start the server might be:" }}

 java -Xmx1024M -Xms1024M \
     -Dminecraft.api.env=custom \
@@ -141,24 +132,24 @@ java -Xmx1024M -Xms1024M \
     -Dminecraft.api.services.host={{ .App.ServicesURL }} \
     -jar server.jar nogui
-

Minecraft 1.7.2 through 1.15.2

+

{{ call .T "Minecraft 1.7.2 through 1.15.2" }}

-

- Refer to the authlib-injector documentation on setting up a server: - https://github.com/yushijinhun/authlib-injector/blob/develop/README.en.md#deploy. -

+

{{ call .T + `Refer to the authlib-injector documentation on setting up a server.` + "https://github.com/yushijinhun/authlib-injector/blob/develop/README.en.md#deploy" + }}

-

- Alternatively, you can patch your server to use a newer version of Mojang's authlib that supports the arguments for custom API servers. Replace the files under com/mojang/authlib in your server.jar with the files in authlib-1.6.25.jar. -

+

{{ call .T + `Alternatively, you can patch your server to use a newer version of Mojang's authlib that supports the arguments for custom API servers. Replace the files under com/mojang/authlib in your server.jar with the files in authlib-1.6.25.jar.` + "https://libraries.minecraft.net/com/mojang/authlib/1.6.25/authlib-1.6.25.jar" + }}

-

Late Classic, Alpha, Beta, etc. through Minecraft 1.6.4

+

{{ call .T `Late Classic, Alpha, Beta, etc. through Minecraft 1.6.4` "https://minecraft.wiki/w/Java_Edition_Late_Classic" }}

-

- Use OnlineModeFix and start the server with the -Dminecraft.api.session.host argument described above. For example, the full command you use to start the server might be: +

{{ call .T + `Use %s and start the server with the -Dminecraft.api.session.host argument described above. For example, the full command you use to start the server might be:` + (html `OnlineModeFix`) + }}

 java -Xmx1024M -Xms1024M \