1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-09-04 11:58:05 +00:00

Categories: Localized titles

This commit is contained in:
Timur Ismagilov
2022-04-02 00:59:47 +03:00
parent 9d971871eb
commit 0ab4bb5846
3 changed files with 22 additions and 21 deletions

View File

@@ -1,4 +1,5 @@
{{define "title"}}Category list{{end}} {{define "category list"}}Category list{{end}}
{{define "title"}}{{template "category list"}}{{end}}
{{define "body"}} {{define "body"}}
<main class="main-width category-list"> <main class="main-width category-list">
<h1>{{template "title"}}</h1> <h1>{{template "title"}}</h1>

View File

@@ -1,4 +1,5 @@
{{define "title"}}Category {{.CatName | beautifulName}}{{end}} {{define "category x"}}Category {{. | beautifulName}}{{end}}
{{define "title"}}{{template "category x" .CatName}}{{end}}
{{define "body"}} {{define "body"}}
{{$catName := .CatName}} {{$catName := .CatName}}
<main class="main-width category"> <main class="main-width category">

View File

@@ -9,7 +9,7 @@ import (
"text/template" // TODO: Fight "text/template" // TODO: Fight
) )
const categoriesRu = ` const ruTranslation = `
{{define "empty cat"}}Эта категория пуста.{{end}} {{define "empty cat"}}Эта категория пуста.{{end}}
{{define "add hypha"}}Добавить в категорию{{end}} {{define "add hypha"}}Добавить в категорию{{end}}
{{define "cat"}}Категория{{end}} {{define "cat"}}Категория{{end}}
@@ -18,7 +18,7 @@ const categoriesRu = `
{{define "placeholder"}}Имя категории...{{end}} {{define "placeholder"}}Имя категории...{{end}}
{{define "remove from category title"}}Убрать гифу из этой категории{{end}} {{define "remove from category title"}}Убрать гифу из этой категории{{end}}
{{define "add to category title"}}Добавить гифу в эту категорию{{end}} {{define "add to category title"}}Добавить гифу в эту категорию{{end}}
{{define "category list heading"}}Список категорий{{end}} {{define "category list"}}Список категорий{{end}}
{{define "no categories"}}В этой вики нет категорий.{{end}} {{define "no categories"}}В этой вики нет категорий.{{end}}
{{define "category x"}}Категория {{. | beautifulName}}{{end}} {{define "category x"}}Категория {{. | beautifulName}}{{end}}
` `
@@ -26,31 +26,29 @@ const categoriesRu = `
var ( var (
//go:embed *.html //go:embed *.html
fs embed.FS fs embed.FS
m = template.Must
baseEn, baseRu *template.Template
viewListChain, viewPageChain, viewCardChain viewutil.Chain viewListChain, viewPageChain, viewCardChain viewutil.Chain
) )
func prepareViews() { func prepareViews() {
var (
baseEn = m(viewutil.BaseEn.Clone()) m = template.Must
baseRu = m(viewutil.BaseRu.Clone()) copyEnWith = func(f string) *template.Template {
return m(m(viewutil.BaseEn.Clone()).ParseFS(fs, f))
}
copyRuWith = func(f string) *template.Template {
return m(m(viewutil.BaseRu.Clone()).ParseFS(fs, f))
}
)
viewCardChain = viewutil. viewCardChain = viewutil.
En( En(copyEnWith("view_card.html")).
m(m(baseEn.Clone()).ParseFS(fs, "view_card.html"))). Ru(m(copyRuWith("view_card.html").Parse(ruTranslation)))
Ru(
m(m(m(baseRu.Clone()).ParseFS(fs, "view_card.html")).Parse(categoriesRu)))
viewListChain = viewutil. viewListChain = viewutil.
En( En(copyEnWith("view_list.html")).
m(m(baseEn.Clone()).ParseFS(fs, "view_list.html"))). Ru(m(copyRuWith("view_list.html").Parse(ruTranslation)))
Ru(
m(m(m(baseRu.Clone()).ParseFS(fs, "view_list.html")).Parse(categoriesRu)))
viewPageChain = viewutil. viewPageChain = viewutil.
En( En(copyEnWith("view_page.html")).
m(m(baseEn.Clone()).ParseFS(fs, "view_page.html"))). Ru(m(copyRuWith("view_page.html").Parse(ruTranslation)))
Ru(
m(m(m(baseRu.Clone()).ParseFS(fs, "view_page.html")).Parse(categoriesRu)))
} }
type cardData struct { type cardData struct {
@@ -59,6 +57,7 @@ type cardData struct {
GivenPermissionToModify bool GivenPermissionToModify bool
} }
// CategoryCard is the little sidebar that is shown nearby the hypha view.
func CategoryCard(meta viewutil.Meta, hyphaName string) string { func CategoryCard(meta viewutil.Meta, hyphaName string) string {
var buf strings.Builder var buf strings.Builder
err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{ err := viewCardChain.Get(meta).ExecuteTemplate(&buf, "category card", cardData{