From 5009a8b04c33fa120959fd30768b8d4be9d0febb Mon Sep 17 00:00:00 2001 From: Azareal Date: Tue, 27 Nov 2018 17:40:13 +1000 Subject: [PATCH] Optimise away some more bits we don't need for guests and members. --- common/phrases/phrases.go | 18 +++++++++++++++++- templates/topic_alt.html | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/phrases/phrases.go b/common/phrases/phrases.go index f8e502de..39a808ba 100644 --- a/common/phrases/phrases.go +++ b/common/phrases/phrases.go @@ -48,7 +48,8 @@ type LanguagePack struct { UserAgents map[string]string OperatingSystems map[string]string HumanLanguages map[string]string - Errors map[string]string + Errors map[string]string // Temp stand-in + ErrorsBytes map[string][]byte NoticePhrases map[string]string PageTitles map[string]string TmplPhrases map[string]string @@ -85,6 +86,11 @@ func InitPhrases(lang string) error { return err } + langPack.ErrorsBytes = make(map[string][]byte) + for name, phrase := range langPack.Errors { + langPack.ErrorsBytes[name] = []byte(phrase) + } + // [prefix][name]phrase langPack.TmplPhrasesPrefixes = make(map[string]map[string]string) for name, phrase := range langPack.TmplPhrases { @@ -222,6 +228,13 @@ func GetErrorPhrase(name string) string { } return res } +func GetErrorPhraseBytes(name string) []byte { + res, ok := currentLangPack.Load().(*LanguagePack).ErrorsBytes[name] + if !ok { + return getPlaceholderBytes("error", name) + } + return res +} func GetNoticePhrase(name string) string { res, ok := currentLangPack.Load().(*LanguagePack).NoticePhrases[name] @@ -275,6 +288,9 @@ func GetTmplPhrasesByPrefix(prefix string) (phrases map[string]string, ok bool) func getPlaceholder(prefix string, suffix string) string { return "{lang." + prefix + "[" + suffix + "]}" } +func getPlaceholderBytes(prefix string, suffix string) []byte { + return []byte("{lang." + prefix + "[" + suffix + "]}") +} // Please don't mutate *LanguagePack func GetCurrentLangPack() *LanguagePack { diff --git a/templates/topic_alt.html b/templates/topic_alt.html index 87d2722f..eb985fcf 100644 --- a/templates/topic_alt.html +++ b/templates/topic_alt.html @@ -75,7 +75,7 @@
{{.Topic.ContentHTML}}
- + {{if .CurrentUser.Loggedin}}{{if .CurrentUser.Perms.EditTopic}}{{end}}{{end}}
{{if .CurrentUser.Loggedin}}