From d80fb242dbde0ab7ea5a84e40118ca6fc1e873a0 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 16 Jul 2025 15:45:43 +0200 Subject: [PATCH] refactor(template): reduce translation-related introspection Keys in translation maps are always strings, never anything else, so there is no need to introspect them. --- internal/template/engine.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/internal/template/engine.go b/internal/template/engine.go index 1013a118..e4a3746b 100644 --- a/internal/template/engine.go +++ b/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