From 40bb20a89c30caa8e15129b18418274fa294efe0 Mon Sep 17 00:00:00 2001 From: Timur Ismagilov Date: Sun, 20 Mar 2022 22:24:40 +0300 Subject: [PATCH] L10n experiment no. 6 (?) Use the template system for default English keys and then redefine them with Russian versions. This is kinda weird. --- views/categories.go | 13 ++++++++++++- views/categories.html | 13 ++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/views/categories.go b/views/categories.go index 73b1c9a..54cf349 100644 --- a/views/categories.go +++ b/views/categories.go @@ -13,6 +13,13 @@ import ( //go:embed categories.html var fs embed.FS +const categoriesRu = ` +{{define "empty cat"}}Эта категория пуста.{{end}} +{{define "add hypha"}}Добавить в категорию{{end}} +{{define "cat"}}Категория{{end}} +{{define "hypha name"}}Имя гифы{{end}} +` + var ( categoryT *template.Template ) @@ -44,7 +51,11 @@ func categoryCardHTML(hyphaName string) string { func CategoryPageHTML(meta Meta, catName string) { var buf strings.Builder - err := categoryT.ExecuteTemplate(&buf, "category page", struct { + var t, _ = categoryT.Clone() + if meta.Lc.Locale == "ru" { + _, _ = t.Parse(categoriesRu) + } + err := t.ExecuteTemplate(&buf, "category page", struct { CatName string Hyphae []string }{ diff --git a/views/categories.html b/views/categories.html index 1614d76..6eac0fe 100644 --- a/views/categories.html +++ b/views/categories.html @@ -29,11 +29,9 @@ {{define "category page"}} {{$catName := .CatName}}
-

Category {{$catName}}

- {{if len .Hyphae}} -

This page lists all hyphae in the category.

- {{else}} -

This category has no hyphae.

+

{{block "cat" .}}Category{{end}} {{beautifulName $catName}}

+ {{if len .Hyphae | not}} +

{{block "empty cat" .}}This category is empty{{end}}

{{end}}