From 66414952e8555099cb90b10b36a3aa4d465e9773 Mon Sep 17 00:00:00 2001 From: partisan Date: Fri, 30 May 2025 17:04:57 +0200 Subject: [PATCH] Fixed 'Error parsing template: template: privacy.html:27: function "translate"' --- common.go | 9 +++++++++ main.go | 17 +---------------- templates/privacy.html | 2 +- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/common.go b/common.go index 326c01c..75baf40 100755 --- a/common.go +++ b/common.go @@ -173,3 +173,12 @@ func FormatLinkHTML(rawURL string) LinkParts { return lp } + +// Converts any struct to a map[string]interface{} using JSON round-trip. +// Useful for rendering templates with generic map input. +func toMap(data interface{}) map[string]interface{} { + jsonBytes, _ := json.Marshal(data) + var result map[string]interface{} + _ = json.Unmarshal(jsonBytes, &result) + return result +} diff --git a/main.go b/main.go index 5038b6c..a9019e4 100755 --- a/main.go +++ b/main.go @@ -282,20 +282,5 @@ func handlePrivacyPage(w http.ResponseWriter, r *http.Request) { LanguageOptions: languageOptions, } - // Parse the template - tmpl, err := template.New("privacy.html").ParseFiles("templates/privacy.html") - if err != nil { - log.Printf("Error parsing template: %v", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - return - } - - // Set the response content type - w.Header().Set("Content-Type", "text/html; charset=utf-8") - - // Execute the template - if err := tmpl.Execute(w, data); err != nil { - log.Printf("Error executing template: %v", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - } + renderTemplate(w, "privacy.html", toMap(data)) } diff --git a/templates/privacy.html b/templates/privacy.html index 1b7e58c..1cd9029 100644 --- a/templates/privacy.html +++ b/templates/privacy.html @@ -64,7 +64,7 @@ alt="QGato" >

{{ translate "site_name" }}

-

{{ translate "site_description" }

+

{{ translate "site_description" }}