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.
This commit is contained in:
@@ -40,6 +40,9 @@ func (icons) Parse(parent ast.Node, block text.Reader, pc parser.Context) ast.No
|
||||
// The source text is kept so a name the theme does not know can be written back exactly as the author
|
||||
// typed it, rather than vanishing from the middle of a sentence.
|
||||
n := &iconNode{name: name, literal: string(line[:width])}
|
||||
if origin, ok := render.OriginFrom(pc); ok {
|
||||
n.lang = origin.Lang
|
||||
}
|
||||
block.Advance(width)
|
||||
return n
|
||||
}
|
||||
@@ -52,6 +55,7 @@ type iconNode struct {
|
||||
ast.BaseInline
|
||||
name string
|
||||
literal string
|
||||
lang string
|
||||
}
|
||||
|
||||
func (n *iconNode) Kind() ast.NodeKind { return iconKind }
|
||||
@@ -65,7 +69,7 @@ func (f fragments) renderIcon(w util.BufWriter, source []byte, n ast.Node, enter
|
||||
return ast.WalkContinue, nil
|
||||
}
|
||||
call := n.(*iconNode)
|
||||
out, err := f.partial(iconFragment, render.Fragment{Args: map[string]string{"name": call.name}})
|
||||
out, err := f.partial(iconFragment, render.Fragment{Args: map[string]string{"name": call.name}, Lang: call.lang})
|
||||
if err != nil {
|
||||
slog.Error("skipping icon", "name", call.name, "err", err)
|
||||
out = nil
|
||||
|
||||
Reference in New Issue
Block a user