diff options
author | Thomas Voss <mail@thomasvoss.com> | 2025-08-02 01:20:00 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2025-08-02 01:20:00 +0200 |
commit | 37df33e09316c105294d4a73cf56819b9a738a8c (patch) | |
tree | 7959165a55dcb13dd63f11417aac197ea5f8544a /src | |
parent | 0ffd1750d956db35c6f741e19d3210f216eb9cb8 (diff) |
Improve table formatting
Diffstat (limited to 'src')
-rw-r--r-- | src/templates.go | 23 | ||||
-rw-r--r-- | src/templates/coins-designs-ee.html.tmpl | 92 |
2 files changed, 61 insertions, 54 deletions
diff --git a/src/templates.go b/src/templates.go index a3bc52d..ec081f1 100644 --- a/src/templates.go +++ b/src/templates.go @@ -33,6 +33,7 @@ var ( "safe": asHTML, "toUpper": strings.ToUpper, "tuple": templateMakeTuple, + "withTranslation": withTranslation, "withTranslations": withTranslations, } ) @@ -119,6 +120,28 @@ func ifElse(b bool, x, y any) any { return y } +func withTranslation(tag, bcp, text string, trans template.HTML) template.HTML { + var bob strings.Builder + bob.WriteByte('<') + bob.WriteString(tag) + bob.WriteString(`><span lang="`) + bob.WriteString(bcp) + bob.WriteString(`">`) + bob.WriteString(text) + bob.WriteString("</span>") + + if text != string(trans) { + bob.WriteString(`<br><span class="translation">`) + bob.WriteString(string(trans)) + bob.WriteString("</span>") + } + + bob.WriteString("</") + bob.WriteString(tag) + bob.WriteByte('>') + return template.HTML(bob.String()) +} + func withTranslations(tag string, text string, translations ...[]any) template.HTML { var bob strings.Builder bob.WriteByte('<') diff --git a/src/templates/coins-designs-ee.html.tmpl b/src/templates/coins-designs-ee.html.tmpl index ad1a1dc..b478ff3 100644 --- a/src/templates/coins-designs-ee.html.tmpl +++ b/src/templates/coins-designs-ee.html.tmpl @@ -36,122 +36,106 @@ <thead> <tr> <th data-numeric style="width: 1%">{{ .Get "Position" }}</th> - <th>{{ .Get "Name" }}<br>{{ .Get "Translation" }}</th> + <th> + {{ .Get "Name" }}<br> + <span class="translation">{{ .Get "Translation" }}</span> + </th> <th>{{ .Get "Author(s)" }}</th> <th data-numeric>{{ .Get "Votes" }}</th> <th data-numeric>{{ .Get "Votes (%)" }}</th> </tr> </thead> <tbody> - {{ $args := (map "Break" "<br>") }} + {{ $args := map "Break" "<br>" }} <tr> <td data-numeric>1</td> - {{/* TRANSLATORS: This is a place name. If you’re translating for a latin-script language, translate this to ‘{Null}’, otherwise transliterate this into your respective alphabet. */}} - <td>Hara 2{{ .Get "{Break:r}Hara 2" $args }}</td> + {{/* TRANSLATORS: Name of a coin design. Don’t translate unless you use a non-latin script */}} + {{ withTranslation "td" "et" "Hara 2" + (.Get "Hara 2") }} <td>{{ .Get "Lembit Lõhmus" }}</td> <td data-numeric>{{ .Printer.Itoa 12482 }}</td> - <td data-numeric>{{ .Printer.Ftoa 27.46 }}</td> + <td data-numeric>{{ .Printer.Ftop 27.46 }}</td> </tr> <tr> <td data-numeric>2</td> - <td> - <span lang="et">Järjepidevus</span> - {{/* TRANSLATORS: Estonian translators should replace the entire translation with ‘{Null}’ */}} - {{ .Get "{Break:r}Consistency" $args }} - </td> + {{ withTranslation "td" "et" "Järjepidevus" + (.Get "Consistency") }} <td>{{ .Get "Tiit Jürna" }}</td> <td data-numeric>{{ .Printer.Itoa 7477 }}</td> - <td data-numeric>{{ .Printer.Ftoa 16.45 }}</td> + <td data-numeric>{{ .Printer.Ftop 16.45 }}</td> </tr> <tr> <td data-numeric>3</td> - <td> - <span lang="la">In corpore</span> - {{ .Get "{Break:r}In the Body" $args }} - </td> + {{ withTranslation "td" "la" "In corpore" + (.Get "In the Body") }} <td>{{ .Get "Jaan Meristo" }}</td> <td data-numeric>{{ .Printer.Itoa 7284 }}</td> - <td data-numeric>{{ .Printer.Ftoa 16.03 }}</td> + <td data-numeric>{{ .Printer.Ftop 16.03 }}</td> </tr> <tr> <td data-numeric>4</td> - <td> - Tomson 5791 - {{/* TRANSLATORS: This name. If you’re translating for a latin-script language, translate this to ‘{Null}’, otherwise transliterate this into your respective alphabet. */}} - {{ .Get "{Break:r}Tomson 5791" $args }} - </td> + {{/* TRANSLATORS: Name of a coin design. Don’t translate unless you use a non-latin script */}} + {{ withTranslation "td" "et" "Tomson 5791" + (.Get "Tomson 5791") }} <td>{{ .Get "Taavi Torim" }}</td> <td data-numeric>{{ .Printer.Itoa 6219 }}</td> - <td data-numeric>{{ .Printer.Ftoa 13.68 }}</td> + <td data-numeric>{{ .Printer.Ftop 13.68 }}</td> </tr> <tr> <td data-numeric>5</td> - <td> - <span lang="et">Eesti keel</span> - {{/* TRANSLATORS: Estonian translators should replace the entire translation with ‘{Null}’ */}} - {{ .Get "{Break:r}Estonian" $args }} - </td> + {{/* TRANSLATORS: Name of a coin design. Don’t translate unless you use a non-latin script */}} + {{ withTranslation "td" "et" "Eesti keel" + (.GetC "Estonian" "Language Name") }} <td>{{ .Get "Jaak Peep, Villem Valme" }}</td> <td data-numeric>{{ .Printer.Itoa 5997 }}</td> - <td data-numeric>{{ .Printer.Ftoa 13.19 }}</td> + <td data-numeric>{{ .Printer.Ftop 13.19 }}</td> </tr> <tr> <td data-numeric>6</td> <td>261948</td> <td>{{ .Get "Mai Järmut, Villu Järmut" }}</td> <td data-numeric>{{ .Printer.Itoa 3036 }}</td> - <td data-numeric>{{ .Printer.Ftoa 6.68 }}</td> + <td data-numeric>{{ .Printer.Ftop 6.68 }}</td> </tr> <tr> <td data-numeric>7</td> - <td> - <span lang="et">Linnutee</span> - {{/* TRANSLATORS: Estonian translators should replace the entire translation with ‘{Null}’ */}} - {{ .Get "{Break:r}Bird Road" $args }} - </td> + {{ withTranslation "td" "et" "Linnutee" + (.Get "Bird Road") }} <td>{{ .Get "Tiit Jürna" }}</td> <td data-numeric>{{ .Printer.Itoa 1323 }}</td> - <td data-numeric>{{ .Printer.Ftoa 2.91 }}</td> + <td data-numeric>{{ .Printer.Ftop 2.91 }}</td> </tr> <tr> <td data-numeric>8</td> - <td> - <span lang="et">Leopardid-2</span> - {{/* TRANSLATORS: Estonian translators should replace the entire translation with ‘{Null}’ */}} - {{ .Get "{Break:r}Leopards-2" $args }} - </td> + {{ withTranslation "td" "et" "Leopardid-2" + (.Get "Leopards-2") }} <td>{{ .Get "Jaarno Ester" }}</td> <td data-numeric>{{ .Printer.Itoa 759 }}</td> - <td data-numeric>{{ .Printer.Ftoa 1.67 }}</td> + <td data-numeric>{{ .Printer.Ftop 1.67 }}</td> </tr> <tr> <td data-numeric>9</td> - <td> - Nova - {{/* TRANSLATORS: This name. If you’re translating for a latin-script language, translate this to ‘{Null}’, otherwise transliterate this into your respective alphabet. */}} - {{ .Get "{Break:r}Nova" $args }} - </td> + {{/* TRANSLATORS: Name of a coin design. Don’t translate unless you use a non-latin script */}} + {{ withTranslation "td" "et" "Nova" + (.Get "Nova") }} <td>{{ .Get "Rene Haljasmäe" }}</td> <td data-numeric>{{ .Printer.Itoa 498 }}</td> - <td data-numeric>{{ .Printer.Ftoa 1.1 }}</td> + <td data-numeric>{{ .Printer.Ftop 1.1 }}</td> </tr> <tr> <td data-numeric>10</td> - <td> - <span lang="et">Lill rukkis</span> - {{/* TRANSLATORS: Estonian translators should replace the entire translation with ‘{Null}’ */}} - {{ .Get "{Break:r}A Flower in the Rye" $args }} - </td> + {{ withTranslation "td" "et" "Lill rukkis" + (.Get "A Flower in the Rye") }} <td>{{ .Get "Margus Kadarik" }}</td> <td data-numeric>{{ .Printer.Itoa 378 }}</td> - <td data-numeric>{{ .Printer.Ftoa 0.83 }}</td> + <td data-numeric>{{ .Printer.Ftop 0.83 }}</td> </tr> </tbody> <tfoot> <tr> <th colspan="3">{{ .Get "Total" }}</th> <th data-numeric>{{ .Printer.Itoa 45453 }}</th> - <th data-numeric>{{ .Printer.Ftoa 100.0 }}</th> + <th data-numeric>{{ .Printer.Ftop 100.0 }}</th> </tr> </tfoot> </table> |