Use the langpack's isocode in header.html instead of en.

Added the GetLangPack function.
This commit is contained in:
Azareal 2019-04-09 17:21:00 +10:00
parent e9f1a3c677
commit 733a802357
4 changed files with 10 additions and 1 deletions

View File

@ -42,6 +42,7 @@ type Header struct {
//OGImage string //OGImage string
OGDesc string OGDesc string
GoogSiteVerify string GoogSiteVerify string
IsoCode string
LooseCSP bool LooseCSP bool
StartedAt time.Time StartedAt time.Time
Elapsed1 string Elapsed1 string

View File

@ -151,6 +151,10 @@ func SaveLangPack(langPack *LanguagePack) error {
return nil return nil
} }
func GetLangPack() *LanguagePack {
return currentLangPack.Load().(*LanguagePack)
}
func GetLevelPhrase(level int) string { func GetLevelPhrase(level int) string {
levelPhrases := currentLangPack.Load().(*LanguagePack).Levels levelPhrases := currentLangPack.Load().(*LanguagePack).Levels
if len(levelPhrases.Levels) > 0 && level < len(levelPhrases.Levels) { if len(levelPhrases.Levels) > 0 && level < len(levelPhrases.Levels) {

View File

@ -7,6 +7,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/Azareal/Gosora/common/phrases"
) )
// nolint // nolint
@ -114,6 +116,7 @@ func panelUserCheck(w http.ResponseWriter, r *http.Request, user *User) (header
Hooks: GetHookTable(), Hooks: GetHookTable(),
Zone: "panel", Zone: "panel",
Writer: w, Writer: w,
IsoCode: phrases.GetLangPack().IsoCode,
} }
// TODO: We should probably initialise header.ExtData // TODO: We should probably initialise header.ExtData
// ? - Should we only show this in debug mode? It might be useful for detecting issues in production, if we show it there as-well // ? - Should we only show this in debug mode? It might be useful for detecting issues in production, if we show it there as-well
@ -207,6 +210,7 @@ func userCheck(w http.ResponseWriter, r *http.Request, user *User) (header *Head
Hooks: GetHookTable(), Hooks: GetHookTable(),
Zone: "frontend", Zone: "frontend",
Writer: w, Writer: w,
IsoCode: phrases.GetLangPack().IsoCode,
} }
header.GoogSiteVerify = header.Settings["google_site_verify"].(string) header.GoogSiteVerify = header.Settings["google_site_verify"].(string)

View File

@ -1,5 +1,5 @@
<!doctype html> <!doctype html>
<html lang="en"> <html{{if .Header.IsoCode}} lang="{{.Header.IsoCode}}"{{end}}>
<head> <head>
<title>{{.Title}} | {{.Header.Site.Name}}</title> <title>{{.Title}} | {{.Header.Site.Name}}</title>
{{range .Header.Stylesheets}} {{range .Header.Stylesheets}}