1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-31 19:39:09 +00:00

L10n experiment no. 6 (?)

Use the template system for default English keys and then redefine them with Russian versions.

This is kinda weird.
This commit is contained in:
Timur Ismagilov 2022-03-20 22:24:40 +03:00
parent 15496ec02a
commit 40bb20a89c
2 changed files with 18 additions and 8 deletions

View File

@ -13,6 +13,13 @@ import (
//go:embed categories.html //go:embed categories.html
var fs embed.FS var fs embed.FS
const categoriesRu = `
{{define "empty cat"}}Эта категория пуста.{{end}}
{{define "add hypha"}}Добавить в категорию{{end}}
{{define "cat"}}Категория{{end}}
{{define "hypha name"}}Имя гифы{{end}}
`
var ( var (
categoryT *template.Template categoryT *template.Template
) )
@ -44,7 +51,11 @@ func categoryCardHTML(hyphaName string) string {
func CategoryPageHTML(meta Meta, catName string) { func CategoryPageHTML(meta Meta, catName string) {
var buf strings.Builder 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 CatName string
Hyphae []string Hyphae []string
}{ }{

View File

@ -29,11 +29,9 @@
{{define "category page"}} {{define "category page"}}
{{$catName := .CatName}} {{$catName := .CatName}}
<main class="main-width category"> <main class="main-width category">
<h1>Category <i>{{$catName}}</i></h1> <h1>{{block "cat" .}}Category{{end}} <i>{{beautifulName $catName}}</i></h1>
{{if len .Hyphae}} {{if len .Hyphae | not}}
<p>This page lists all hyphae in the category.</p> <p>{{block "empty cat" .}}This category is empty{{end}}</p>
{{else}}
<p>This category has no hyphae.</p>
{{end}} {{end}}
<ul class="category__entries"> <ul class="category__entries">
{{range .Hyphae}} {{range .Hyphae}}
@ -43,10 +41,11 @@
{{end}} {{end}}
<li class="category__entry category__add-to-cat"> <li class="category__entry category__add-to-cat">
<form method="POST" action="/add-to-category" class="category__add-form"> <form method="POST" action="/add-to-category" class="category__add-form">
<input type="text" name="hypha" id="_hypha-name" placeholder="Hypha name"> <input type="text" name="hypha" id="_hypha-name"
placeholder="{{block `hypha name` .}}Hypha name{{end}}">
<input type="hidden" name="cat" value="{{$catName}}"> <input type="hidden" name="cat" value="{{$catName}}">
<input type="hidden" name="redirect-to" value="/category/{{$catName}}"> <input type="hidden" name="redirect-to" value="/category/{{$catName}}">
<input type="submit" value="Add hypha to category"> <input type="submit" value="{{block `add hypha` .}}Add to the category{{end}}">
</form> </form>
</li> </li>
</ul> </ul>