i18n root, footer

This commit is contained in:
Evan Goode 2025-07-06 22:22:32 -04:00
parent e95280c8fd
commit 95ca36950e
6 changed files with 199 additions and 74 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"bytes"
"context" "context"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
@ -16,6 +17,7 @@ import (
"github.com/zitadel/oidc/v3/pkg/oidc" "github.com/zitadel/oidc/v3/pkg/oidc"
"golang.org/x/text/language" "golang.org/x/text/language"
"gorm.io/gorm" "gorm.io/gorm"
"html"
"html/template" "html/template"
"io" "io"
"log" "log"
@ -66,6 +68,8 @@ func NewTemplate(app *App) *Template {
} }
funcMap := template.FuncMap{ funcMap := template.FuncMap{
"render": RenderHTML,
"html": func(x string) template.HTML { return template.HTML(x) },
"PrimaryPlayerSkinURL": app.PrimaryPlayerSkinURL, "PrimaryPlayerSkinURL": app.PrimaryPlayerSkinURL,
"PlayerSkinURL": app.PlayerSkinURL, "PlayerSkinURL": app.PlayerSkinURL,
"InviteURL": app.InviteURL, "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 { type baseContext struct {
T func(string, ...interface{}) template.HTML
App *App App *App
L *gotext.Locale L *gotext.Locale
URL string URL string
@ -165,10 +185,28 @@ type baseContext struct {
ErrorMessage string 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 { 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{ return baseContext{
App: app, App: app,
L: (*c).Get(CONTEXT_KEY_LOCALE).(*gotext.Locale), L: l,
T: T,
URL: (*c).Request().URL.RequestURI(), URL: (*c).Request().URL.RequestURI(),
SuccessMessage: app.lastSuccessMessage(c), SuccessMessage: app.lastSuccessMessage(c),
WarningMessage: app.lastWarningMessage(c), WarningMessage: app.lastWarningMessage(c),

View File

@ -14,3 +14,99 @@ msgstr "Cuenta de %s"
msgid "Log out" msgid "Log out"
msgstr "Cerrar sesión" 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 <a href=\"%s\">the authlib-injector documentation on setting up a server</a>."
msgstr "Consulta <a href=\"%s\">la documentación de authlib-injector sobre cómo configurar un servidor</a>."
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 <code>com/mojang/authlib</code> in your <code>server.jar</code> with the files in <a href=\"%s\">authlib-1.6.25.jar</a>."
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 <code>com/mojang/authlib</code> en tu <code>server.jar</code> con los archivos en <a href=\"%s\">authlib-1.6.25.jar</a>."
msgid "<a href=\"%s\">Late Classic</a>, Alpha, Beta, etc. through Minecraft 1.6.4"
msgstr "<a href=\"%s\">Clásico Tardío</a>, Alpha, Beta, etc. hasta Minecraft 1.6.4"
msgid "Use %s and start the server with the <code>-Dminecraft.api.session.host</code> 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 <code>-Dminecraft.api.session.host</code> 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 "<a href=\"%s\">Source code</a>."
msgstr "<a href=\"%s\">Código fuente</a>."

View File

@ -2,9 +2,9 @@
{{ if .App.Config.EnableFooter }} {{ if .App.Config.EnableFooter }}
<hr /> <hr />
<small> <small>
Drasl version {{ .App.Constants.Version }}. Licensed under {{ call .T `Drasl version %s.` .App.Constants.Version }}
<a href="{{ .App.Constants.LicenseURL }}">{{ .App.Constants.License }}</a>. {{ call .T `Licensed as %s.` (render `<a href="{{ index . 0 }}">{{ index . 1 }}</a>` .App.Constants.LicenseURL .App.Constants.License) }}
Source code <a href="{{ .App.Constants.RepositoryURL }}">here</a>. {{ call .T `<a href="%s">Source code</a>.` .App.Constants.RepositoryURL }}
</small> </small>
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

@ -11,20 +11,20 @@
<div style="text-align: right"> <div style="text-align: right">
{{ if .User }} {{ if .User }}
{{ if .User.IsAdmin }} {{ if .User.IsAdmin }}
<a href="{{ .App.FrontEndURL }}/web/admin">{{ .L.Get "Admin" }}</a> <a href="{{ .App.FrontEndURL }}/web/admin">{{ call .T "Admin" }}</a>
{{ end }} {{ end }}
<a href="{{ .App.FrontEndURL }}/web/user" <a href="{{ .App.FrontEndURL }}/web/user"
>{{ .L.Get "%s's Account" .User.Username }}</a >{{ call .T "%s's Account" .User.Username }}</a
> >
<form <form
style="display: inline" style="display: inline"
action="{{ .App.FrontEndURL }}/web/logout" action="{{ .App.FrontEndURL }}/web/logout"
method="post" method="post"
> >
<input type="submit" value="{{ .L.Get "Log out" }}" /> <input type="submit" value="{{ call .T "Log out" }}" />
</form> </form>
{{ else }} {{ else }}
<a href="{{ .App.FrontEndURL }}/web/registration">{{ .L.Get "Register" }}</a> <a href="{{ .App.FrontEndURL }}/web/registration">{{ call .T "Register" }}</a>
{{ end }} {{ end }}
</div> </div>
</nav> </nav>

View File

@ -1,6 +1,6 @@
{{ define "base" }} {{ define "base" }}
<!doctype html> <!doctype html>
<html lang="en"> <html lang="{{ .L.GetLanguage }}">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />

View File

@ -4,7 +4,10 @@
{{ define "content" }} {{ define "content" }}
{{ template "header" . }} {{ template "header" . }}
<h3>Log in</h3>
{{ $authlibInjectorA := render `<a href="{{ index . 0}}">{{ index . 1}}</a>` .App.AuthlibInjectorURL .App.AuthlibInjectorURL }}
<h3>{{ call .T "Log in" }}</h3>
{{ $dividerNeeded := false }} {{ $dividerNeeded := false }}
@ -16,7 +19,7 @@
<h3><img class="openid-logo" src="{{ .App.PublicURL }}/openid-logo.svg" alt="OpenID logo"></h3> <h3><img class="openid-logo" src="{{ .App.PublicURL }}/openid-logo.svg" alt="OpenID logo"></h3>
{{ range $provider := $.WebOIDCProviders }} {{ range $provider := $.WebOIDCProviders }}
<p> <p>
<a href="{{ $provider.AuthURL }}">Sign in with {{ $provider.Name }}</a> <a href="{{ $provider.AuthURL }}">{{ call $.T "Sign in with %s" $provider.Name }}</a>
</p> </p>
{{ end }} {{ end }}
{{ $dividerNeeded = true }} {{ $dividerNeeded = true }}
@ -24,106 +27,94 @@
{{ if .App.Config.AllowPasswordLogin }} {{ if .App.Config.AllowPasswordLogin }}
{{ if $dividerNeeded }} {{ if $dividerNeeded }}
<div class="divider">or</div> <div class="divider">{{ call .T "or" }}</div>
{{ $dividerNeeded = false }} {{ $dividerNeeded = false }}
{{ end }} {{ end }}
<form action="{{ .App.FrontEndURL }}/web/login" method="post"> <form action="{{ .App.FrontEndURL }}/web/login" method="post">
<input type="text" name="username" placeholder="Username" required /> <input type="text" name="username" placeholder="{{ call .T "Username" }}" required />
<input hidden name="returnUrl" value="{{ .URL }}" /> <input hidden name="returnUrl" value="{{ .URL }}" />
<input hidden name="destination" value="{{ .Destination }}" /> <input hidden name="destination" value="{{ .Destination }}" />
<input <input
class="long" class="long"
type="password" type="password"
name="password" name="password"
placeholder="Password" placeholder="{{ call .T "Password" }}"
required required
/> />
<input type="submit" value="Log in" /> <input type="submit" value="{{ call .T "Log in" }}" />
</form> </form>
{{ $dividerNeeded = true }} {{ $dividerNeeded = true }}
{{ end }} {{ end }}
<h3>Configuring your client</h3> <h3>{{ call .T "Configuring your client" }}</h3>
<p> <p>
Using {{ .App.Config.ApplicationName }} on the client requires a third-party launcher that supports {{ 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."
custom API servers. .App.Config.ApplicationName
<a href="https://github.com/unmojang/FjordLauncher">Fjord Launcher</a>, a (html `<a href="https://github.com/unmojang/FjordLauncher">Fjord Launcher</a>`)
fork of Prism Launcher, is recommended, but (html `<a href="https://github.com/huanghongxun/HMCL">HMCL</a>`) }}
<a href="https://github.com/huanghongxun/HMCL">HMCL</a> also works. Both are
free/libre.
</p> </p>
<h4>Fjord Launcher</h4> <h4>Fjord Launcher</h4>
<ol> <ol>
<li> <li>{{ call .T "Click your account in the top right and select “Manage Accounts...”." }} </li>
Click your account in the top right and select "Manage Accounts...". <li>{{ call .T "Click “Add authlib-injector” in the right-hand sidebar." }}</li>
</li> <li>{{ call .T
<li>Click "Add authlib-injector" in the right-hand sidebar.</li> "Enter your player name and your %s password or Minecraft Token, and use %s for the URL. Click “OK”."
<li> .App.Config.ApplicationName
Enter your player name and your {{ .App.Config.ApplicationName }} password or Minecraft Token, and use $authlibInjectorA
<a href="{{ .App.AuthlibInjectorURL }}">{{ .App.AuthlibInjectorURL }}</a> }}</li>
for the URL. Click "OK".
</li>
</ol> </ol>
<h4>HMCL</h4> <h4>HMCL</h4>
<ol> <ol>
<li>{{ call .T "Go to the “Account List” view by clicking the account at the top of the sidebar." }}</li>
<li> <li>
Go to the "Account List" view by clicking the account at the top of the {{ call .T
sidebar. "At the bottom left, click “New Auth Server” and enter %s. Click “Next” and then “Finish”."
$authlibInjectorA
}}
</li> </li>
<li> <li>
At the bottom left, click "New Auth Server" and enter {{ call .T
<a href="{{ .App.AuthlibInjectorURL }}">{{ .App.AuthlibInjectorURL }}</a>. "In the sidebar, click the newly-added authentication server, labeled “%s”. Enter your %s player name and password and click “Login”."
Click "Next" and then "Finish". .App.Config.InstanceName
</li> .App.Config.ApplicationName
<li> }}
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".
</li> </li>
</ol> </ol>
<h4>Other Launchers</h4> <h4>{{ call .T "Other launchers" }}</h4>
<p> <p>{{ call .T "Use the authlib-injector URL %s." $authlibInjectorA }}</p>
Use the authlib-injector URL
<a href="{{ .App.AuthlibInjectorURL }}">{{ .App.AuthlibInjectorURL }}</a>.
</p>
<p> <p>{{ call .T "Or, if your launcher supports custom API servers but not via authlib-injector, use the following URLs:" }}</p>
Or, if your launcher supports custom API servers but not via
authlib-injector, use the following URLs:
</p>
<table> <table>
<tr> <tr>
<td>Authentication Server:</td> <td>{{ call .T "Authentication server:" }}</td>
<td>{{ .App.AuthURL }}</td> <td>{{ .App.AuthURL }}</td>
</tr> </tr>
<tr> <tr>
<td>Account Server:</td> <td>{{ call .T "Account server:" }}</td>
<td>{{ .App.AccountURL }}</td> <td>{{ .App.AccountURL }}</td>
</tr> </tr>
<tr> <tr>
<td>Session Server:</td> <td>{{ call .T "Session server:" }}</td>
<td>{{ .App.SessionURL }}</td> <td>{{ .App.SessionURL }}</td>
</tr> </tr>
<tr> <tr>
<td>Services Server:</td> <td>{{ call .T "Services server:" }}</td>
<td>{{ .App.ServicesURL }}</td> <td>{{ .App.ServicesURL }}</td>
</tr> </tr>
</table> </table>
<h3>Configuring your server</h3> <h3>{{ call .T "Configuring your server" }}</h3>
<h4>Minecraft 1.16 and later</h4> <h4>{{ call .T "Minecraft 1.16 and later" }}</h4>
On recent versions of Minecraft, you can use {{ .App.Config.ApplicationName }} on an unmodified Vanilla <p>{{ 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:" }}</p>
server. To do so, add the following arguments before you specify the jar file
when you start the server:
<pre style="word-wrap: break-word; white-space: pre-wrap; overflow-x: auto"> <pre style="word-wrap: break-word; white-space: pre-wrap; overflow-x: auto">
-Dminecraft.api.env=custom -Dminecraft.api.env=custom
-Dminecraft.api.auth.host={{ .App.AuthURL }} -Dminecraft.api.auth.host={{ .App.AuthURL }}
@ -131,7 +122,7 @@
-Dminecraft.api.session.host={{ .App.SessionURL }} -Dminecraft.api.session.host={{ .App.SessionURL }}
-Dminecraft.api.services.host={{ .App.ServicesURL }}</pre> -Dminecraft.api.services.host={{ .App.ServicesURL }}</pre>
For example, the full command you use to start the server might be: <p>{{call .T "For example, the full command you use to start the server might be:" }}</p>
<pre style="word-wrap: break-word; white-space: pre-wrap; overflow-x: auto"> <pre style="word-wrap: break-word; white-space: pre-wrap; overflow-x: auto">
java -Xmx1024M -Xms1024M \ java -Xmx1024M -Xms1024M \
-Dminecraft.api.env=custom \ -Dminecraft.api.env=custom \
@ -141,24 +132,24 @@ java -Xmx1024M -Xms1024M \
-Dminecraft.api.services.host={{ .App.ServicesURL }} \ -Dminecraft.api.services.host={{ .App.ServicesURL }} \
-jar server.jar nogui</pre> -jar server.jar nogui</pre>
<h4>Minecraft 1.7.2 through 1.15.2</h4> <h4>{{ call .T "Minecraft 1.7.2 through 1.15.2" }}</h4>
<p> <p>{{ call .T
Refer to the authlib-injector documentation on setting up a server: `Refer to <a href="%s">the authlib-injector documentation on setting up a server</a>.`
<a "https://github.com/yushijinhun/authlib-injector/blob/develop/README.en.md#deploy"
href="https://github.com/yushijinhun/authlib-injector/blob/develop/README.en.md#deploy" }}</p>
>https://github.com/yushijinhun/authlib-injector/blob/develop/README.en.md#deploy</a
>.
</p>
<p> <p>{{ 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 <code>com/mojang/authlib</code> in your <code>server.jar</code> with the files in <a href="https://libraries.minecraft.net/com/mojang/authlib/1.6.25/authlib-1.6.25.jar">authlib-1.6.25.jar</a>. `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 <code>com/mojang/authlib</code> in your <code>server.jar</code> with the files in <a href="%s">authlib-1.6.25.jar</a>.`
</p> "https://libraries.minecraft.net/com/mojang/authlib/1.6.25/authlib-1.6.25.jar"
}}</p>
<h4><a href="https://minecraft.wiki/w/Java_Edition_Late_Classic">Late Classic</a>, Alpha, Beta, etc. through Minecraft 1.6.4</h4> <h4>{{ call .T `<a href="%s">Late Classic</a>, Alpha, Beta, etc. through Minecraft 1.6.4` "https://minecraft.wiki/w/Java_Edition_Late_Classic" }}</h4>
<p> <p>{{ call .T
Use <a href="https://github.com/craftycodie/OnlineModeFix">OnlineModeFix</a> and start the server with the <code>-Dminecraft.api.session.host</code> argument described above. For example, the full command you use to start the server might be: `Use %s and start the server with the <code>-Dminecraft.api.session.host</code> argument described above. For example, the full command you use to start the server might be:`
(html `<a href="https://github.com/craftycodie/OnlineModeFix">OnlineModeFix</a>`)
}}
<pre style="word-wrap: break-word; white-space: pre-wrap; overflow-x: auto"> <pre style="word-wrap: break-word; white-space: pre-wrap; overflow-x: auto">
java -Xmx1024M -Xms1024M \ java -Xmx1024M -Xms1024M \