The portal in English and Turkish: a catalogue per language, a switcher at the foot of every page, landing.language, Turkish numbers and dates
Every template and handler message in internal/web goes through a JSON
catalogue under internal/web/locales/<code>/, with English as the fallback.
The language is the person's choice (a cookie set by /_lang/{code}), else
Accept-Language, else landing.language. Tests refuse a key some language
lacks, a translation with other arguments than English, and template text
left in English.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
30f7f3474a
commit
11231d8c2b
113 files changed
+8091
-1981
No files matched your search
+17
-26
@@ -3,7 +3,6 @@ package web
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -39,7 +38,14 @@ const (
|
||||
// Empty and all-zero series render as an empty frame rather than nothing: a
|
||||
// missing chart reads as a broken page, and a flat one reads as no traffic,
|
||||
// which is the truth.
|
||||
func BarChart(s Series, unit string) template.HTML {
|
||||
//
|
||||
// unit is written after the peak as it is given, so a caller passes it in
|
||||
// the page's language.
|
||||
func BarChart(s Series, unit string) template.HTML { return english.BarChart(s, unit) }
|
||||
|
||||
// BarChart is the chart in this language: its peak, and the words it says
|
||||
// when there is none.
|
||||
func (l *Lang) BarChart(s Series, unit string) template.HTML {
|
||||
if s.Colour == "" {
|
||||
s.Colour = "--accent"
|
||||
}
|
||||
@@ -80,9 +86,9 @@ func BarChart(s Series, unit string) template.HTML {
|
||||
}
|
||||
b.WriteString(`</svg>`)
|
||||
|
||||
peak := fmt.Sprintf("peak %s %s", compact(maxV), unit)
|
||||
peak := l.T("chart.peak_unit", l.Compact(maxV), unit)
|
||||
if maxV == 0 {
|
||||
peak = "nothing recorded"
|
||||
peak = l.T("chart.nothing_recorded")
|
||||
}
|
||||
return template.HTML(`<div class="chart-wrap">` + b.String() + //nolint:gosec // built above
|
||||
`<span class="chart-peak">` + string(escapeText(peak)) + `</span></div>`)
|
||||
@@ -111,28 +117,13 @@ func escapeText(s string) template.HTML {
|
||||
}
|
||||
|
||||
// compact renders a number the way a person reads one at a glance.
|
||||
func compact(v float64) string {
|
||||
switch {
|
||||
case v >= 1e9:
|
||||
return fmt.Sprintf("%.1fB", v/1e9)
|
||||
case v >= 1e6:
|
||||
return fmt.Sprintf("%.1fM", v/1e6)
|
||||
case v >= 1e3:
|
||||
return fmt.Sprintf("%.1fk", v/1e3)
|
||||
case v == float64(int64(v)):
|
||||
return fmt.Sprintf("%d", int64(v))
|
||||
case v > 0 && v < 1:
|
||||
// Two significant digits rather than one decimal place. A spend of
|
||||
// 0.03 printed as "0.0" says nothing was spent, which is the one thing
|
||||
// a figure must not say when something was. Counts never reach this
|
||||
// branch: a whole number is caught above, and zero is whole.
|
||||
return strconv.FormatFloat(v, 'g', 2, 64)
|
||||
default:
|
||||
return fmt.Sprintf("%.1f", v)
|
||||
}
|
||||
}
|
||||
func compact(v float64) string { return english.Compact(v) }
|
||||
|
||||
// hourLabel is what a bar's tooltip says.
|
||||
func hourLabel(t time.Time, v float64, unit string) string {
|
||||
return fmt.Sprintf("%s — %s %s", t.Local().Format("Mon 15:04"), compact(v), unit)
|
||||
func hourLabel(t time.Time, v float64, unit string) string { return english.hourLabel(t, v, unit) }
|
||||
|
||||
// hourLabel names the day the way this language does: "Mon 15:04", "Pzt
|
||||
// 15:04". unit is the caller's, in this language already.
|
||||
func (l *Lang) hourLabel(t time.Time, v float64, unit string) string {
|
||||
return l.T("chart.hour_label", l.Format(t.Local(), "Mon 15:04"), l.Compact(v), unit)
|
||||
}
|
||||
Reference in new issue
Block a user