Explorar el Código

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 hace 8 meses
padre
commit
d80fb242db
Se han modificado 1 ficheros con 3 adiciones y 14 borrados
  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.
-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