mirror of
https://github.com/miniflux/v2.git
synced 2025-08-06 17:41:00 +00:00
refactor(template): reduce translation-related introspection
Keys in translation maps are always strings, never anything else, so there is no need to introspect them.
This commit is contained in:
parent
4336a0bd85
commit
d80fb242db
1 changed files with 3 additions and 14 deletions
|
@ -95,7 +95,7 @@ func (e *Engine) ParseTemplates() error {
|
|||
}
|
||||
|
||||
// Render process a template.
|
||||
func (e *Engine) Render(name string, data map[string]interface{}) []byte {
|
||||
func (e *Engine) Render(name string, data map[string]any) []byte {
|
||||
tpl, ok := e.templates[name]
|
||||
if !ok {
|
||||
panic("This template does not exists: " + name)
|
||||
|
@ -108,19 +108,8 @@ func (e *Engine) Render(name string, data map[string]interface{}) []byte {
|
|||
"elapsed": func(timezone string, t time.Time) string {
|
||||
return elapsedTime(printer, timezone, t)
|
||||
},
|
||||
"t": func(key interface{}, args ...interface{}) string {
|
||||
switch k := key.(type) {
|
||||
case string:
|
||||
return printer.Printf(k, args...)
|
||||
case error:
|
||||
return k.Error()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
},
|
||||
"plural": func(key string, n int, args ...interface{}) string {
|
||||
return printer.Plural(key, n, args...)
|
||||
},
|
||||
"t": printer.Printf,
|
||||
"plural": printer.Plural,
|
||||
})
|
||||
|
||||
var b bytes.Buffer
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue