Files
khosra/examples/demo-site/templates/list.html
T
Claude Opus 5andbdeshi 7136f6e2d9 let a shortcode fragment speak the reader's language
Three fragments added this session needed a word the author did not write: an
untitled :::warn told the reader nothing about being a warning, an untitled
panel fell back to whatever the browser calls <details>, and the contents list
had no label at all — an accessibility gap as much as an untranslated one. None
of them could be fixed, because `t` needs a language and Fragment had none, so
those words could only ever have been English on a site that serves Bengali.

Fragment gains Lang, captured on each call at parse time — a node renderer never
receives the parse context, the same constraint that put pictures and headings
on the node. Five phrase keys follow, and a Bengali page now reads সূচিপত্র,
সতর্কতা and বিস্তারিত where an English one reads Contents, Warning and Details.

The demo's own list.html was the better example of the problem and now shows the
answer: a site's own sentences are not in the engine's phrase table, so a
template needing its own words branches on the language it was given. That is
what theme-contract.md has always told a theme to do, demonstrated rather than
asserted, and a case proves the Bengali listing carries no English.

Two files crossed the size advisory on the way. render.go shed the contract
types to view.go, where state.md already claimed they lived and where the file's
own header said they belonged; shortcodes_test.go split to mirror its sources,
which the one-file-per-source convention already asked for. Both are pure moves.
2026-08-01 23:09:03 +06:00

32 lines
1.5 KiB
HTML

{{define "main" -}}
<h1>{{.Title}}</h1>
{{/* A site's own words are its own to translate: `t` reaches the engine's phrase table, not this file's
sentences, so a template needing its own text branches on the language it was given. */}}
{{- if eq .Lang "bn"}}
<p><em>এই তালিকাটি সাইটের নিজের টেমপ্লেট থেকে তৈরি, যা এমবেড করা টেমপ্লেটের পরে পড়া হয়। এটি একটি নামযুক্ত ব্লক
বদলে দেয় এবং বাকি নথিটি উত্তরাধিকারসূত্রে পায়।</em></p>
{{- else}}
<p><em>This listing is rendered by the site's own template, parsed after the embedded one. It redefines a
single named block and inherits the whole document around it.</em></p>
{{- end}}
{{- if .Items}}
{{- range .Items}}
<article class="entry">
<h2><a href="{{.URL}}">{{if .Title}}{{.Title}}{{else}}{{.Key}}{{end}}</a></h2>
{{- if not .Date.IsZero}}
<p class="meta"><time datetime="{{.Date.Format "2006-01-02"}}">{{day $.Lang .Date}}</time>{{if .Section}} · {{.Section}}{{end}}</p>
{{- end}}
</article>
{{- end}}
{{- else}}
<p>{{t .Lang "empty"}}</p>
{{- end}}
{{- if or .PrevURL .NextURL}}
<nav class="pagination">
{{- if .PrevURL}}<a rel="prev" href="{{.PrevURL}}">{{t .Lang "newer"}}</a>{{end}}
<span>{{t .Lang "page-of" (num .Lang .Page) (num .Lang .Pages)}}</span>
{{- if .NextURL}}<a rel="next" href="{{.NextURL}}">{{t .Lang "older"}}</a>{{end}}
</nav>
{{- end}}
{{- end}}