فهرست منبع

refactor(template): reduce translation-related introspection

Keys in translation maps are always strings, never anything else, so there is
no need to introspect them.
jvoisin 10 ماه پیش
والد
کامیت
d80fb242db
1فایلهای تغییر یافته به همراه3 افزوده شده و 14 حذف شده
  1. 3 14
      internal/template/engine.go

+ 3 - 14
internal/template/engine.go

@@ -95,7 +95,7 @@ func (e *Engine) ParseTemplates() error {
 }
 }
 
 
 // Render process a template.
 // 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]
 	tpl, ok := e.templates[name]
 	if !ok {
 	if !ok {
 		panic("This template does not exists: " + name)
 		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 {
 		"elapsed": func(timezone string, t time.Time) string {
 			return elapsedTime(printer, timezone, t)
 			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
 	var b bytes.Buffer