🌐 Added language support for pages
Some checks failed
/ docker (push) Failing after 44s

This commit is contained in:
Maxim Lebedev 2023-11-08 03:16:12 +06:00
parent 23c7b18315
commit 2c705e6142
Signed by: toby3d
GPG Key ID: 1F14E25B7C119FC5
5 changed files with 263 additions and 142 deletions

View File

@ -62,6 +62,7 @@ func main() {
w.Header().Set(common.HeaderContentType, common.MIMETextHTMLCharsetUTF8) w.Header().Set(common.HeaderContentType, common.MIMETextHTMLCharsetUTF8)
template.WriteTemplate(w, template.NewPage( template.WriteTemplate(w, template.NewPage(
template.NewBaseOf(lang), template.NewBaseOf(lang),
language.English,
[]byte(`hello, world!`), []byte(`hello, world!`),
`toby3d`, `toby3d`,
)) ))

View File

@ -7,6 +7,7 @@
Body() Body()
T(format message.Reference, v ...any) T(format message.Reference, v ...any)
Title() Title()
Lang()
} %} } %}
{% code {% code
@ -34,9 +35,15 @@ func NewBaseOf(lang language.Tag) BaseOf {
{% func (b BaseOf) Body() %}{% endfunc %} {% func (b BaseOf) Body() %}{% endfunc %}
{% func (b BaseOf) Lang() %}
{% if b.language != language.Und %}
{%s b.language.String() %}
{% endif %}
{% endfunc %}
{% func Template(p Pager) %} {% func Template(p Pager) %}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="{%= p.Lang() %}">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">

View File

@ -43,10 +43,16 @@ type Pager interface {
StreamTitle(qw422016 *qt422016.Writer) StreamTitle(qw422016 *qt422016.Writer)
//line web/template/baseof.qtpl:6 //line web/template/baseof.qtpl:6
WriteTitle(qq422016 qtio422016.Writer) WriteTitle(qq422016 qtio422016.Writer)
//line web/template/baseof.qtpl:6
Lang() string
//line web/template/baseof.qtpl:6
StreamLang(qw422016 *qt422016.Writer)
//line web/template/baseof.qtpl:6
WriteLang(qq422016 qtio422016.Writer)
//line web/template/baseof.qtpl:6 //line web/template/baseof.qtpl:6
} }
//line web/template/baseof.qtpl:13 //line web/template/baseof.qtpl:14
type BaseOf struct { type BaseOf struct {
language language.Tag language language.Tag
printer *message.Printer printer *message.Printer
@ -59,140 +65,181 @@ func NewBaseOf(lang language.Tag) BaseOf {
} }
} }
//line web/template/baseof.qtpl:27 //line web/template/baseof.qtpl:28
func (b BaseOf) StreamTitle(qw422016 *qt422016.Writer) { func (b BaseOf) StreamTitle(qw422016 *qt422016.Writer) {
//line web/template/baseof.qtpl:27 //line web/template/baseof.qtpl:28
qw422016.N().S(`toby3d`) qw422016.N().S(`toby3d`)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
} }
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
func (b BaseOf) WriteTitle(qq422016 qtio422016.Writer) { func (b BaseOf) WriteTitle(qq422016 qtio422016.Writer) {
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
b.StreamTitle(qw422016) b.StreamTitle(qw422016)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
} }
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
func (b BaseOf) Title() string { func (b BaseOf) Title() string {
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
b.WriteTitle(qb422016) b.WriteTitle(qb422016)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
return qs422016 return qs422016
//line web/template/baseof.qtpl:29 //line web/template/baseof.qtpl:30
} }
//line web/template/baseof.qtpl:31
func (b BaseOf) StreamT(qw422016 *qt422016.Writer, format message.Reference, v ...any) {
//line web/template/baseof.qtpl:32 //line web/template/baseof.qtpl:32
func (b BaseOf) StreamT(qw422016 *qt422016.Writer, format message.Reference, v ...any) {
//line web/template/baseof.qtpl:33
qw422016.E().S(b.printer.Sprintf(format, v...)) qw422016.E().S(b.printer.Sprintf(format, v...))
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
} }
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
func (b BaseOf) WriteT(qq422016 qtio422016.Writer, format message.Reference, v ...any) { func (b BaseOf) WriteT(qq422016 qtio422016.Writer, format message.Reference, v ...any) {
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
b.StreamT(qw422016, format, v...) b.StreamT(qw422016, format, v...)
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
} }
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
func (b BaseOf) T(format message.Reference, v ...any) string { func (b BaseOf) T(format message.Reference, v ...any) string {
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
b.WriteT(qb422016, format, v...) b.WriteT(qb422016, format, v...)
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
return qs422016 return qs422016
//line web/template/baseof.qtpl:33 //line web/template/baseof.qtpl:34
} }
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
func (b BaseOf) StreamBody(qw422016 *qt422016.Writer) { func (b BaseOf) StreamBody(qw422016 *qt422016.Writer) {
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
} }
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
func (b BaseOf) WriteBody(qq422016 qtio422016.Writer) { func (b BaseOf) WriteBody(qq422016 qtio422016.Writer) {
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
b.StreamBody(qw422016) b.StreamBody(qw422016)
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
} }
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
func (b BaseOf) Body() string { func (b BaseOf) Body() string {
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
b.WriteBody(qb422016) b.WriteBody(qb422016)
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
return qs422016 return qs422016
//line web/template/baseof.qtpl:35 //line web/template/baseof.qtpl:36
} }
//line web/template/baseof.qtpl:37 //line web/template/baseof.qtpl:38
func StreamTemplate(qw422016 *qt422016.Writer, p Pager) { func (b BaseOf) StreamLang(qw422016 *qt422016.Writer) {
//line web/template/baseof.qtpl:37 //line web/template/baseof.qtpl:39
qw422016.N().S(`<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>`) if b.language != language.Und {
//line web/template/baseof.qtpl:44 //line web/template/baseof.qtpl:40
p.StreamTitle(qw422016) qw422016.E().S(b.language.String())
//line web/template/baseof.qtpl:44 //line web/template/baseof.qtpl:41
qw422016.N().S(`</title></head><body>`) }
//line web/template/baseof.qtpl:48 //line web/template/baseof.qtpl:42
p.StreamBody(qw422016)
//line web/template/baseof.qtpl:48
qw422016.N().S(`</body></html>`)
//line web/template/baseof.qtpl:51
} }
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
func WriteTemplate(qq422016 qtio422016.Writer, p Pager) { func (b BaseOf) WriteLang(qq422016 qtio422016.Writer) {
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
StreamTemplate(qw422016, p) b.StreamLang(qw422016)
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
} }
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
func Template(p Pager) string { func (b BaseOf) Lang() string {
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
WriteTemplate(qb422016, p) b.WriteLang(qb422016)
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
return qs422016 return qs422016
//line web/template/baseof.qtpl:51 //line web/template/baseof.qtpl:42
}
//line web/template/baseof.qtpl:44
func StreamTemplate(qw422016 *qt422016.Writer, p Pager) {
//line web/template/baseof.qtpl:44
qw422016.N().S(`<!DOCTYPE html><html lang="`)
//line web/template/baseof.qtpl:46
p.StreamLang(qw422016)
//line web/template/baseof.qtpl:46
qw422016.N().S(`"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>`)
//line web/template/baseof.qtpl:51
p.StreamTitle(qw422016)
//line web/template/baseof.qtpl:51
qw422016.N().S(`</title></head><body>`)
//line web/template/baseof.qtpl:55
p.StreamBody(qw422016)
//line web/template/baseof.qtpl:55
qw422016.N().S(`</body></html>`)
//line web/template/baseof.qtpl:58
}
//line web/template/baseof.qtpl:58
func WriteTemplate(qq422016 qtio422016.Writer, p Pager) {
//line web/template/baseof.qtpl:58
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/baseof.qtpl:58
StreamTemplate(qw422016, p)
//line web/template/baseof.qtpl:58
qt422016.ReleaseWriter(qw422016)
//line web/template/baseof.qtpl:58
}
//line web/template/baseof.qtpl:58
func Template(p Pager) string {
//line web/template/baseof.qtpl:58
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/baseof.qtpl:58
WriteTemplate(qb422016, p)
//line web/template/baseof.qtpl:58
qs422016 := string(qb422016.B)
//line web/template/baseof.qtpl:58
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/baseof.qtpl:58
return qs422016
//line web/template/baseof.qtpl:58
} }

View File

@ -1,13 +1,19 @@
{% import (
"golang.org/x/text/language"
) %}
{% code {% code
type Page struct { type Page struct {
BaseOf BaseOf
language language.Tag
title string title string
content []byte content []byte
} }
func NewPage(base BaseOf, content []byte, title string) Page { func NewPage(base BaseOf, lang language.Tag, content []byte, title string) Page {
return Page{ return Page{
BaseOf: base, BaseOf: base,
language: lang,
title: title, title: title,
content: content, content: content,
} }
@ -23,7 +29,15 @@ func NewPage(base BaseOf, content []byte, title string) Page {
{% endif %} {% endif %}
{% endfunc %} {% endfunc %}
{% func (p Page) Lang() %}
{% if p.language != language.Und %}
{%s p.language.String() %}
{% else %}
{%= p.BaseOf.Lang() %}
{% endif %}
{% endfunc %}
{% func (p Page) Body() %} {% func (p Page) Body() %}
{%z p.content %} <p>{%z p.content %}</p>
{% endfunc %} {% endfunc %}
{% endstripspace %} {% endstripspace %}

View File

@ -5,103 +5,155 @@
package template package template
//line web/template/page.qtpl:1 //line web/template/page.qtpl:1
import (
"golang.org/x/text/language"
)
//line web/template/page.qtpl:5
import ( import (
qtio422016 "io" qtio422016 "io"
qt422016 "github.com/valyala/quicktemplate" qt422016 "github.com/valyala/quicktemplate"
) )
//line web/template/page.qtpl:1 //line web/template/page.qtpl:5
var ( var (
_ = qtio422016.Copy _ = qtio422016.Copy
_ = qt422016.AcquireByteBuffer _ = qt422016.AcquireByteBuffer
) )
//line web/template/page.qtpl:2 //line web/template/page.qtpl:6
type Page struct { type Page struct {
BaseOf BaseOf
title string language language.Tag
content []byte title string
content []byte
} }
func NewPage(base BaseOf, content []byte, title string) Page { func NewPage(base BaseOf, lang language.Tag, content []byte, title string) Page {
return Page{ return Page{
BaseOf: base, BaseOf: base,
title: title, language: lang,
content: content, title: title,
content: content,
} }
} }
//line web/template/page.qtpl:18 //line web/template/page.qtpl:24
func (p Page) StreamTitle(qw422016 *qt422016.Writer) { func (p Page) StreamTitle(qw422016 *qt422016.Writer) {
//line web/template/page.qtpl:19 //line web/template/page.qtpl:25
if p.title != "" { if p.title != "" {
//line web/template/page.qtpl:20
qw422016.E().S(p.title)
//line web/template/page.qtpl:21
} else {
//line web/template/page.qtpl:22
p.BaseOf.StreamTitle(qw422016)
//line web/template/page.qtpl:23
}
//line web/template/page.qtpl:24
}
//line web/template/page.qtpl:24
func (p Page) WriteTitle(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:24
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:24
p.StreamTitle(qw422016)
//line web/template/page.qtpl:24
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:24
}
//line web/template/page.qtpl:24
func (p Page) Title() string {
//line web/template/page.qtpl:24
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:24
p.WriteTitle(qb422016)
//line web/template/page.qtpl:24
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:24
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:24
return qs422016
//line web/template/page.qtpl:24
}
//line web/template/page.qtpl:26 //line web/template/page.qtpl:26
func (p Page) StreamBody(qw422016 *qt422016.Writer) { qw422016.E().S(p.title)
//line web/template/page.qtpl:27 //line web/template/page.qtpl:27
qw422016.E().Z(p.content) } else {
//line web/template/page.qtpl:28 //line web/template/page.qtpl:28
p.BaseOf.StreamTitle(qw422016)
//line web/template/page.qtpl:29
}
//line web/template/page.qtpl:30
} }
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
func (p Page) WriteBody(qq422016 qtio422016.Writer) { func (p Page) WriteTitle(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
qw422016 := qt422016.AcquireWriter(qq422016) qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
p.StreamBody(qw422016) p.StreamTitle(qw422016)
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
qt422016.ReleaseWriter(qw422016) qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
} }
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
func (p Page) Body() string { func (p Page) Title() string {
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
qb422016 := qt422016.AcquireByteBuffer() qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
p.WriteBody(qb422016) p.WriteTitle(qb422016)
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
qs422016 := string(qb422016.B) qs422016 := string(qb422016.B)
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
qt422016.ReleaseByteBuffer(qb422016) qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
return qs422016 return qs422016
//line web/template/page.qtpl:28 //line web/template/page.qtpl:30
}
//line web/template/page.qtpl:32
func (p Page) StreamLang(qw422016 *qt422016.Writer) {
//line web/template/page.qtpl:33
if p.language != language.Und {
//line web/template/page.qtpl:34
qw422016.E().S(p.language.String())
//line web/template/page.qtpl:35
} else {
//line web/template/page.qtpl:36
p.BaseOf.StreamLang(qw422016)
//line web/template/page.qtpl:37
}
//line web/template/page.qtpl:38
}
//line web/template/page.qtpl:38
func (p Page) WriteLang(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:38
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:38
p.StreamLang(qw422016)
//line web/template/page.qtpl:38
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:38
}
//line web/template/page.qtpl:38
func (p Page) Lang() string {
//line web/template/page.qtpl:38
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:38
p.WriteLang(qb422016)
//line web/template/page.qtpl:38
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:38
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:38
return qs422016
//line web/template/page.qtpl:38
}
//line web/template/page.qtpl:40
func (p Page) StreamBody(qw422016 *qt422016.Writer) {
//line web/template/page.qtpl:40
qw422016.N().S(`<p>`)
//line web/template/page.qtpl:41
qw422016.E().Z(p.content)
//line web/template/page.qtpl:41
qw422016.N().S(`</p>`)
//line web/template/page.qtpl:42
}
//line web/template/page.qtpl:42
func (p Page) WriteBody(qq422016 qtio422016.Writer) {
//line web/template/page.qtpl:42
qw422016 := qt422016.AcquireWriter(qq422016)
//line web/template/page.qtpl:42
p.StreamBody(qw422016)
//line web/template/page.qtpl:42
qt422016.ReleaseWriter(qw422016)
//line web/template/page.qtpl:42
}
//line web/template/page.qtpl:42
func (p Page) Body() string {
//line web/template/page.qtpl:42
qb422016 := qt422016.AcquireByteBuffer()
//line web/template/page.qtpl:42
p.WriteBody(qb422016)
//line web/template/page.qtpl:42
qs422016 := string(qb422016.B)
//line web/template/page.qtpl:42
qt422016.ReleaseByteBuffer(qb422016)
//line web/template/page.qtpl:42
return qs422016
//line web/template/page.qtpl:42
} }