Archived
1
0

Merge branch 'master' of ssh://github.com/majestrate/nntpchan

This commit is contained in:
Jeff Becker 2018-10-26 07:28:33 -04:00
commit a6b15674c6
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
4 changed files with 32 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"log"
"path/filepath"
"strings"
"errors"
)
type I18N struct {
@ -22,6 +23,7 @@ type I18N struct {
}
var I18nProvider *I18N = nil
var ErrNoLang = errors.New("no such language")
//Read all .ini files in dir, where the filenames are BCP 47 tags
//Use the language matcher to get the best match for the locale preference
@ -41,17 +43,23 @@ func NewI18n(locale, dir string) (*I18N, error) {
return nil, err
}
found:= false
serverLangs := make([]language.Tag, 1)
serverLangs[0] = language.AmericanEnglish // en-US fallback
// serverLangs[0] = language.AmericanEnglish // en-US fallback
for _, file := range files {
if filepath.Ext(file.Name()) == ".ini" {
name := strings.TrimSuffix(file.Name(), ".ini")
tag, err := language.Parse(name)
if err == nil {
serverLangs = append(serverLangs, tag)
found = true;
}
}
}
if !found {
return nil, ErrNoLang
}
matcher := language.NewMatcher(serverLangs)
tag, _, _ := matcher.Match(pref)

View File

@ -51,6 +51,7 @@ func (self *nullHandler) GetI18N(r *http.Request) *I18N {
i, err = NewI18n(lang, self.translations)
if err != nil {
log.Println(err)
return nil
}
if i != nil {
self.i18n[lang] = i
@ -64,7 +65,10 @@ func (self *nullHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
sfw := strings.Count(r.URL.RawQuery, "sfw=1") > 0
i18n := self.GetI18N(r)
if i18n == nil {
w.WriteHeader(http.StatusNotFound)
return
}
path := r.URL.Path
_, file := filepath.Split(path)

View File

@ -538,3 +538,16 @@ background-repeat: repeat;
border: solid #333 1px;
padding-left: 1em;
}
:target {
background-color: #493769;
}
body {
display: inline-flex;
flex-direction: column;
flex-wrap: wrap;
flex-flow: wrap;
}

View File

@ -848,3 +848,8 @@ th > label {
.spoiler:hover a:hover {
color: #0066FF;
}
:target {
background-color: #493769;
}