1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-04 18:19:54 +00:00

Experiment № 3. QTPL+l10nEntry

Encapsulate translations, but still use QTPL. Hmm
This commit is contained in:
Timur Ismagilov 2022-02-27 13:44:47 +03:00
parent 4494f2677e
commit bd6b46f346
7 changed files with 553 additions and 500 deletions

View File

@ -93,10 +93,6 @@
"about_title": "About {{.name}}",
"users_title": "User list",
"users_heading": "List of users",
"users_admins": "Admins",
"users_moderators": "Moderators",
"users_editors": "Editors",
"no_rights": "Not enough rights",
"reindex_no_rights": "You must be an admin to reindex hyphae.",

View File

@ -96,10 +96,6 @@
"about_title": "О {{.name}}",
"users_title": "Список пользователей",
"users_heading": "Список пользователей",
"users_admins": "Администраторы",
"users_moderators": "Модераторы",
"users_editors": "Редакторы",
"no_rights": "Недостаточно прав",
"reindex_no_rights": "Вы должны быть администратором, чтобы переиндексировать гифы.",

View File

@ -14,6 +14,10 @@ type l10nEntry struct {
_ru string
}
func en(v string) l10nEntry {
return e().en(v)
}
func e() l10nEntry {
return l10nEntry{}
}

View File

@ -1,6 +1,5 @@
{% import "fmt" %}
{% import "path/filepath" %}
{% import "sort" %}
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
{% import "github.com/bouncepaw/mycorrhiza/hyphae" %}
@ -165,59 +164,13 @@ It outputs a poorly formatted JSON, but it works and is valid.
<a class="help-topic-badge" href="/help/en/{%s topic %}">?</a>
{% endfunc %}
{% func UserListHTML(lc *l18n.Localizer) %}
<div class="layout">
<main class="main-width user-list">
<h1>{%s lc.Get("ui.users_heading") %}</h1>
{% code
var (
admins = make([]string, 0)
moderators = make([]string, 0)
editors = make([]string, 0)
)
for u := range user.YieldUsers() {
switch u.Group {
case "admin":
admins = append(admins, u.Name)
case "moderator":
moderators = append(moderators, u.Name)
case "editor", "trusted":
editors = append(editors, u.Name)
}
}
sort.Strings(admins)
sort.Strings(moderators)
sort.Strings(editors)
%}
<section>
<h2>{%s lc.Get("ui.users_admins") %}</h2>
<ol>{% for _, name := range admins %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
<section>
<h2>{%s lc.Get("ui.users_moderators") %}</h2>
<ol>{% for _, name := range moderators %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
<section>
<h2>{%s lc.Get("ui.users_editors") %}</h2>
<ol>{% for _, name := range editors %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
</main>
</div>
{% endfunc %}
{% func HyphaListHTML(lc *l18n.Localizer) %}
<div class="layout">
<main class="main-width">
<h1>{%s lc.Get("ui.list_heading") %}</h1>
<p>{%s lc.GetPlural("ui.list_desc", hyphae.Count()) %}</p>
<ul class="hypha-list">
{% code
{% code
hyphaNames := make(chan string)
sortedHypha := hyphae.PathographicSort(hyphaNames)
for hypha := range hyphae.YieldExistingHyphae() {

File diff suppressed because it is too large Load Diff

64
views/user_list.qtpl Normal file
View File

@ -0,0 +1,64 @@
{% import "github.com/bouncepaw/mycorrhiza/cfg" %}
{% import "github.com/bouncepaw/mycorrhiza/l18n" %}
{% import "github.com/bouncepaw/mycorrhiza/user" %}
{% import "sort" %}
{% code
var hyphaListL10n = map[string]l10nEntry{
"heading": en("List of users").ru("Список пользователей"),
"administrators": en("Administrators").ru("Администраторы"),
"moderators": en("Moderators").ru("Модераторы"),
"editors": en("Editors").ru("Редакторы"),
}
%}
{% func UserListHTML(lc *l18n.Localizer) %}
<div class="layout">
<main class="main-width user-list">
{% code
var get = func(key string) string {
return hyphaListL10n[key].get(lc.Locale)
}
var (
admins = make([]string, 0)
moderators = make([]string, 0)
editors = make([]string, 0)
)
for u := range user.YieldUsers() {
switch u.Group {
// What if we place the users into sorted slices?
case "admin":
admins = append(admins, u.Name)
case "moderator":
moderators = append(moderators, u.Name)
case "editor", "trusted":
editors = append(editors, u.Name)
}
}
sort.Strings(admins)
sort.Strings(moderators)
sort.Strings(editors)
%}
<h1>{%s get("heading") %}</h1>
<section>
<h2>{%s get("administrators") %}</h2>
<ol>{% for _, name := range admins %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
<section>
<h2>{%s get("moderators") %}</h2>
<ol>{% for _, name := range moderators %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
<section>
<h2>{%s get("editors") %}</h2>
<ol>{% for _, name := range editors %}
<li><a href="/hypha/{%s cfg.UserHypha %}/{%s name %}">{%s name %}</a></li>
{% endfor %}</ol>
</section>
</main>
</div>
{% endfunc %}

199
views/user_list.qtpl.go Normal file
View File

@ -0,0 +1,199 @@
// Code generated by qtc from "user_list.qtpl". DO NOT EDIT.
// See https://github.com/valyala/quicktemplate for details.
//line views/user_list.qtpl:1
package views
//line views/user_list.qtpl:1
import "github.com/bouncepaw/mycorrhiza/cfg"
//line views/user_list.qtpl:2
import "github.com/bouncepaw/mycorrhiza/l18n"
//line views/user_list.qtpl:3
import "github.com/bouncepaw/mycorrhiza/user"
//line views/user_list.qtpl:4
import "sort"
//line views/user_list.qtpl:6
import (
qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate"
)
//line views/user_list.qtpl:6
var (
_ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer
)
//line views/user_list.qtpl:7
var hyphaListL10n = map[string]l10nEntry{
"heading": en("List of users").ru("Список пользователей"),
"administrators": en("Administrators").ru("Администраторы"),
"moderators": en("Moderators").ru("Модераторы"),
"editors": en("Editors").ru("Редакторы"),
}
//line views/user_list.qtpl:15
func StreamUserListHTML(qw422016 *qt422016.Writer, lc *l18n.Localizer) {
//line views/user_list.qtpl:15
qw422016.N().S(`
<div class="layout">
<main class="main-width user-list">
`)
//line views/user_list.qtpl:19
var get = func(key string) string {
return hyphaListL10n[key].get(lc.Locale)
}
var (
admins = make([]string, 0)
moderators = make([]string, 0)
editors = make([]string, 0)
)
for u := range user.YieldUsers() {
switch u.Group {
// What if we place the users into sorted slices?
case "admin":
admins = append(admins, u.Name)
case "moderator":
moderators = append(moderators, u.Name)
case "editor", "trusted":
editors = append(editors, u.Name)
}
}
sort.Strings(admins)
sort.Strings(moderators)
sort.Strings(editors)
//line views/user_list.qtpl:42
qw422016.N().S(`
<h1>`)
//line views/user_list.qtpl:43
qw422016.E().S(get("heading"))
//line views/user_list.qtpl:43
qw422016.N().S(`</h1>
<section>
<h2>`)
//line views/user_list.qtpl:45
qw422016.E().S(get("administrators"))
//line views/user_list.qtpl:45
qw422016.N().S(`</h2>
<ol>`)
//line views/user_list.qtpl:46
for _, name := range admins {
//line views/user_list.qtpl:46
qw422016.N().S(`
<li><a href="/hypha/`)
//line views/user_list.qtpl:47
qw422016.E().S(cfg.UserHypha)
//line views/user_list.qtpl:47
qw422016.N().S(`/`)
//line views/user_list.qtpl:47
qw422016.E().S(name)
//line views/user_list.qtpl:47
qw422016.N().S(`">`)
//line views/user_list.qtpl:47
qw422016.E().S(name)
//line views/user_list.qtpl:47
qw422016.N().S(`</a></li>
`)
//line views/user_list.qtpl:48
}
//line views/user_list.qtpl:48
qw422016.N().S(`</ol>
</section>
<section>
<h2>`)
//line views/user_list.qtpl:51
qw422016.E().S(get("moderators"))
//line views/user_list.qtpl:51
qw422016.N().S(`</h2>
<ol>`)
//line views/user_list.qtpl:52
for _, name := range moderators {
//line views/user_list.qtpl:52
qw422016.N().S(`
<li><a href="/hypha/`)
//line views/user_list.qtpl:53
qw422016.E().S(cfg.UserHypha)
//line views/user_list.qtpl:53
qw422016.N().S(`/`)
//line views/user_list.qtpl:53
qw422016.E().S(name)
//line views/user_list.qtpl:53
qw422016.N().S(`">`)
//line views/user_list.qtpl:53
qw422016.E().S(name)
//line views/user_list.qtpl:53
qw422016.N().S(`</a></li>
`)
//line views/user_list.qtpl:54
}
//line views/user_list.qtpl:54
qw422016.N().S(`</ol>
</section>
<section>
<h2>`)
//line views/user_list.qtpl:57
qw422016.E().S(get("editors"))
//line views/user_list.qtpl:57
qw422016.N().S(`</h2>
<ol>`)
//line views/user_list.qtpl:58
for _, name := range editors {
//line views/user_list.qtpl:58
qw422016.N().S(`
<li><a href="/hypha/`)
//line views/user_list.qtpl:59
qw422016.E().S(cfg.UserHypha)
//line views/user_list.qtpl:59
qw422016.N().S(`/`)
//line views/user_list.qtpl:59
qw422016.E().S(name)
//line views/user_list.qtpl:59
qw422016.N().S(`">`)
//line views/user_list.qtpl:59
qw422016.E().S(name)
//line views/user_list.qtpl:59
qw422016.N().S(`</a></li>
`)
//line views/user_list.qtpl:60
}
//line views/user_list.qtpl:60
qw422016.N().S(`</ol>
</section>
</main>
</div>
`)
//line views/user_list.qtpl:64
}
//line views/user_list.qtpl:64
func WriteUserListHTML(qq422016 qtio422016.Writer, lc *l18n.Localizer) {
//line views/user_list.qtpl:64
qw422016 := qt422016.AcquireWriter(qq422016)
//line views/user_list.qtpl:64
StreamUserListHTML(qw422016, lc)
//line views/user_list.qtpl:64
qt422016.ReleaseWriter(qw422016)
//line views/user_list.qtpl:64
}
//line views/user_list.qtpl:64
func UserListHTML(lc *l18n.Localizer) string {
//line views/user_list.qtpl:64
qb422016 := qt422016.AcquireByteBuffer()
//line views/user_list.qtpl:64
WriteUserListHTML(qb422016, lc)
//line views/user_list.qtpl:64
qs422016 := string(qb422016.B)
//line views/user_list.qtpl:64
qt422016.ReleaseByteBuffer(qb422016)
//line views/user_list.qtpl:64
return qs422016
//line views/user_list.qtpl:64
}