mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
Do not use shared variable to translate templates
This commit is contained in:
parent
6b360d08c1
commit
ddd3af4b85
21 changed files with 104 additions and 101 deletions
|
@ -12,17 +12,14 @@ import (
|
|||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/miniflux/miniflux/config"
|
||||
"github.com/miniflux/miniflux/errors"
|
||||
"github.com/miniflux/miniflux/filter"
|
||||
"github.com/miniflux/miniflux/http/route"
|
||||
"github.com/miniflux/miniflux/locale"
|
||||
"github.com/miniflux/miniflux/url"
|
||||
)
|
||||
|
||||
type funcMap struct {
|
||||
cfg *config.Config
|
||||
router *mux.Router
|
||||
Language *locale.Language
|
||||
cfg *config.Config
|
||||
router *mux.Router
|
||||
}
|
||||
|
||||
func (f *funcMap) Map() template.FuncMap {
|
||||
|
@ -77,30 +74,21 @@ func (f *funcMap) Map() template.FuncMap {
|
|||
"isodate": func(ts time.Time) string {
|
||||
return ts.Format("2006-01-02 15:04:05")
|
||||
},
|
||||
"dict": dict,
|
||||
|
||||
// These functions are overrided at runtime after the parsing.
|
||||
"elapsed": func(timezone string, t time.Time) string {
|
||||
return elapsedTime(f.Language, timezone, t)
|
||||
return ""
|
||||
},
|
||||
"t": func(key interface{}, args ...interface{}) string {
|
||||
switch key.(type) {
|
||||
case string:
|
||||
return f.Language.Get(key.(string), args...)
|
||||
case errors.LocalizedError:
|
||||
return key.(errors.LocalizedError).Localize(f.Language)
|
||||
case *errors.LocalizedError:
|
||||
return key.(*errors.LocalizedError).Localize(f.Language)
|
||||
case error:
|
||||
return key.(error).Error()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"plural": func(key string, n int, args ...interface{}) string {
|
||||
return f.Language.Plural(key, n, args...)
|
||||
return ""
|
||||
},
|
||||
"dict": dict,
|
||||
}
|
||||
}
|
||||
|
||||
func newFuncMap(cfg *config.Config, router *mux.Router, language *locale.Language) *funcMap {
|
||||
return &funcMap{cfg, router, language}
|
||||
func newFuncMap(cfg *config.Config, router *mux.Router) *funcMap {
|
||||
return &funcMap{cfg, router}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue