fix HTML in i18n strings

previously it just worked on errors
This commit is contained in:
Henry 2021-05-12 08:03:10 +02:00
parent 4558b208ee
commit 336596552e
5 changed files with 15 additions and 13 deletions

View File

@ -83,10 +83,10 @@ type errorTemplateData struct {
BackURL string BackURL string
} }
func localizeError(ih *i18n.Localizer, err error) (int, string) { func localizeError(ih *i18n.Localizer, err error) (int, template.HTML) {
// default, unlocalized message // default, unlocalized message
msg := err.Error() msg := template.HTML(err.Error())
// localize some specific error messages // localize some specific error messages
var ( var (

View File

@ -3,6 +3,7 @@ package errors
import ( import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"html/template"
"net/http" "net/http"
"github.com/gorilla/sessions" "github.com/gorilla/sessions"
@ -38,7 +39,7 @@ const (
type FlashMessage struct { type FlashMessage struct {
Kind FlashKind Kind FlashKind
Message string Message template.HTML
} }
// TODO: rethink error return - maybe panic() / maybe render package? // TODO: rethink error return - maybe panic() / maybe render package?

View File

@ -58,7 +58,7 @@ AuthFallbackInstruct = "Diese Methode ist ein akzeptabler Fallback, wenn Sie ein
AuthFallbackNewPassword="Neues Passwort" AuthFallbackNewPassword="Neues Passwort"
AuthFallbackRepeatPassword="Passwort wiederholen" AuthFallbackRepeatPassword="Passwort wiederholen"
AuthFallbackPasswordChangeFormTitle = "Passwort ändern" AuthFallbackPasswordChangeFormTitle = "Passwort ändern"
AuthFallbackPasswordChangeWelcome = "Hier können Sie ihr Passwort neu setzen. Bitte achten sie darauf, dass es länger als 10 Zeichen ist. Durch die doppelte eingabe wird sichergestellt, dass Sie sich nicht vertippt haben. Auserdem verwenden wir die Datenbank von haveibeenpwned.com um sicher zu stellen, dass Sie kein unsicherers Passwort verwenden, ohne es zu wissen." AuthFallbackPasswordChangeWelcome = "Hier können Sie ihr Passwort neu setzen. Bitte achten sie darauf, dass es länger als 10 Zeichen ist. Durch die doppelte eingabe wird sichergestellt, dass Sie sich nicht vertippt haben. Auserdem verwenden wir die Datenbank von <a href='https://haveibeenpwned.com'>haveibeenpwned.com</a> um sicher zu stellen, dass Sie kein unsicherers Passwort verwenden, ohne es zu wissen."
AuthFallbackPasswordUpdated = "Das Passwort wurde aktualisiert. Sie können sich nun damit Einloggen." AuthFallbackPasswordUpdated = "Das Passwort wurde aktualisiert. Sie können sich nun damit Einloggen."
AdminMemberPasswordResetLinkCreatedTitle = "Passwort reset link erstellt" AdminMemberPasswordResetLinkCreatedTitle = "Passwort reset link erstellt"
AdminMemberPasswordResetLinkCreatedInstruct = "Der reset Link wurde erstellt. Bitte senden Sie ihn, uber einen geeigneten Seitenkanal wie z.B. E-Mail, an das Mitglied. Wenn die Person den Link offnet, ist Sie in der Lage sich ein neues Passwort zu geben." AdminMemberPasswordResetLinkCreatedInstruct = "Der reset Link wurde erstellt. Bitte senden Sie ihn, uber einen geeigneten Seitenkanal wie z.B. E-Mail, an das Mitglied. Wenn die Person den Link offnet, ist Sie in der Lage sich ein neues Passwort zu geben."

View File

@ -65,7 +65,7 @@ AuthFallbackInstruct = "This method is an acceptable fallback, if you have a use
AuthFallbackNewPassword="New Password" AuthFallbackNewPassword="New Password"
AuthFallbackRepeatPassword="Repeat Password" AuthFallbackRepeatPassword="Repeat Password"
AuthFallbackPasswordChangeFormTitle = "Change Password" AuthFallbackPasswordChangeFormTitle = "Change Password"
AuthFallbackPasswordChangeWelcome = "Here you can change your fallback password. Please make sure it's longer then 10 characters. Via the repition we make sure that you don't accidentally mistype it. Additionally we use the lookup from haveibeenpwned.com to make sure you don't accidentally use a weak password." AuthFallbackPasswordChangeWelcome = "Here you can change your fallback password. Please make sure it's longer then 10 characters. Via the repition we make sure that you don't accidentally mistype it. Additionally we use the lookup from <a href='https://haveibeenpwned.com'>haveibeenpwned.com</a> to make sure you don't accidentally use a weak password."
AuthFallbackPasswordUpdated = "The password was updated. You can now use it to sign in." AuthFallbackPasswordUpdated = "The password was updated. You can now use it to sign in."
AdminMemberPasswordResetLinkCreatedTitle = "Password reset token created" AdminMemberPasswordResetLinkCreatedTitle = "Password reset token created"
AdminMemberPasswordResetLinkCreatedInstruct = "The reset token was created. Please send it to the member via some means (like E-Mail or another suitable side-channel). When they open it, they will be able to choose a new password for themselves." AdminMemberPasswordResetLinkCreatedInstruct = "The reset token was created. Please send it to the member via some means (like E-Mail or another suitable side-channel). When they open it, they will be able to choose a new password for themselves."

View File

@ -5,6 +5,7 @@ package i18n
import ( import (
"fmt" "fmt"
"html/template"
"io" "io"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
@ -248,30 +249,30 @@ func (h Helper) GetRenderFuncs() []render.Option {
return opts return opts
} }
func (l Localizer) LocalizeSimple(messageID string) string { func (l Localizer) LocalizeSimple(messageID string) template.HTML {
msg, err := l.loc.Localize(&i18n.LocalizeConfig{ msg, err := l.loc.Localize(&i18n.LocalizeConfig{
MessageID: messageID, MessageID: messageID,
}) })
if err == nil { if err == nil {
return msg return template.HTML(msg)
} }
panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err)) panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err))
} }
func (l Localizer) LocalizeWithData(messageID string, tplData map[string]string) string { func (l Localizer) LocalizeWithData(messageID string, tplData map[string]string) template.HTML {
msg, err := l.loc.Localize(&i18n.LocalizeConfig{ msg, err := l.loc.Localize(&i18n.LocalizeConfig{
MessageID: messageID, MessageID: messageID,
TemplateData: tplData, TemplateData: tplData,
}) })
if err == nil { if err == nil {
return msg return template.HTML(msg)
} }
panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err)) panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err))
} }
func (l Localizer) LocalizePlurals(messageID string, pluralCount int) string { func (l Localizer) LocalizePlurals(messageID string, pluralCount int) template.HTML {
msg, err := l.loc.Localize(&i18n.LocalizeConfig{ msg, err := l.loc.Localize(&i18n.LocalizeConfig{
MessageID: messageID, MessageID: messageID,
PluralCount: pluralCount, PluralCount: pluralCount,
@ -280,20 +281,20 @@ func (l Localizer) LocalizePlurals(messageID string, pluralCount int) string {
}, },
}) })
if err == nil { if err == nil {
return msg return template.HTML(msg)
} }
panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err)) panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err))
} }
func (l Localizer) LocalizePluralsWithData(messageID string, pluralCount int, tplData map[string]string) string { func (l Localizer) LocalizePluralsWithData(messageID string, pluralCount int, tplData map[string]string) template.HTML {
msg, err := l.loc.Localize(&i18n.LocalizeConfig{ msg, err := l.loc.Localize(&i18n.LocalizeConfig{
MessageID: messageID, MessageID: messageID,
PluralCount: pluralCount, PluralCount: pluralCount,
TemplateData: tplData, TemplateData: tplData,
}) })
if err == nil { if err == nil {
return msg return template.HTML(msg)
} }
panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err)) panic(fmt.Sprintf("i18n/error: failed to localize label %s: %s", messageID, err))