diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/i18n.go | 41 | ||||
-rw-r--r-- | src/templates/coins-designs-ad.html.tmpl | 16 | ||||
-rw-r--r-- | src/templates/coins-mintages.html.tmpl | 4 | ||||
-rw-r--r-- | src/templates/collecting-vending.html.tmpl | 4 |
4 files changed, 43 insertions, 22 deletions
diff --git a/src/i18n.go b/src/i18n.go index 0ebcedc..017dbf7 100644 --- a/src/i18n.go +++ b/src/i18n.go @@ -5,11 +5,14 @@ package src import ( "fmt" + "log" "strings" "time" "golang.org/x/text/language" "golang.org/x/text/message" + + "git.thomasvoss.com/euro-cash.eu/src/email" ) type Printer struct { @@ -235,28 +238,36 @@ func (p Printer) Date(d time.Time) string { return d.Format(p.Locale.dateFmt) } -func (p Printer) M(val float64, round bool) string { - var valstr string +func (p Printer) M(val any) string { + var vstr string /* Hack to avoid gotext writing these two ‘translations’ into the translations file */ f := p.inner.Sprintf - if round { - valstr = f("%d", int(val)) - } else { - valstr = f("%.2f", val) + + switch val.(type) { + case int: + vstr = f("%d", val) + case float64: + vstr = f("%.2f", val) + default: + if err := email.ServerError(badMType{"TODO"}); err != nil { + log.Print(err) + } + /* Hopefully this never happens */ + vstr = "ERROR" } /* All Eurozone languages place the eurosign after the value except - for Dutch, English, Gaelic, and Maltese. Austrian German also + for Dutch, English, Irish, and Maltese. Austrian German also uses Dutch-style formatting, but we do not support that dialect. */ switch p.Locale.Bcp { case "en", "en-US", "ga", "mt": - return fmt.Sprintf("€%s", valstr) + return fmt.Sprintf("€%s", vstr) case "nl": - return fmt.Sprintf("€ %s", valstr) + return fmt.Sprintf("€ %s", vstr) default: - return fmt.Sprintf("%s €", valstr) + return fmt.Sprintf("%s €", vstr) } } @@ -264,3 +275,13 @@ func (p Printer) M(val float64, round bool) string { func (l locale) Language() string { return l.Bcp[:2] } + +type badMType struct { + inner any +} + +func (e badMType) Error() string { + return fmt.Sprintf( + "Attempted to format ‘%v’ of type ‘%T’ as a monetary value in Printer.M()", + e.inner, e.inner) +} diff --git a/src/templates/coins-designs-ad.html.tmpl b/src/templates/coins-designs-ad.html.tmpl index 1effaeb..c42930a 100644 --- a/src/templates/coins-designs-ad.html.tmpl +++ b/src/templates/coins-designs-ad.html.tmpl @@ -23,16 +23,16 @@ </p> <dl> <dt>{{ .T "%s, %s, and %s" - (.Printer.M 0.01 false) - (.Printer.M 0.02 false) - (.Printer.M 0.05 false) }}</dt> + (.Printer.M 0.01) + (.Printer.M 0.02) + (.Printer.M 0.05) }}</dt> <dd>{{ .T "Andorran landscapes, nature, fauna, and flora" }}</dd> <dt>{{ .T "%s, %s, and %s" - (.Printer.M 0.10 false) - (.Printer.M 0.20 false) - (.Printer.M 0.50 false) }}</dt> + (.Printer.M 0.10) + (.Printer.M 0.20) + (.Printer.M 0.50) }}</dt> <dd>{{ .T "Andorra’s Romanesque art" }}</dd> - <dt>{{ .Printer.M 1.00 false }}</dt> + <dt>{{ .Printer.M 1.00 }}</dt> <dd>{{ .T "Casa de la Vall" }}</dd> </dl> <p> @@ -88,4 +88,4 @@ ` `<span lang="la">` `</span>` }} </p> </main> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/coins-mintages.html.tmpl b/src/templates/coins-mintages.html.tmpl index 4ac29e8..8c60248 100644 --- a/src/templates/coins-mintages.html.tmpl +++ b/src/templates/coins-mintages.html.tmpl @@ -73,7 +73,7 @@ <th>{{ .T "Year" }}</th> {{ with $p := .Printer }} {{ range denoms }} - <th>{{ $p.M . false }}</th> + <th>{{ $p.M . }}</th> {{ end }} {{ end }} </thead> @@ -157,4 +157,4 @@ /> {{ index . 2 }} </label> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/src/templates/collecting-vending.html.tmpl b/src/templates/collecting-vending.html.tmpl index 5fcfd0c..2bfea22 100644 --- a/src/templates/collecting-vending.html.tmpl +++ b/src/templates/collecting-vending.html.tmpl @@ -107,7 +107,7 @@ if you throw in five euros. You can try to go above the limit if you throw in, say, %s and then another one- or two euro coin; the machine will probably accept it. - ` (.Printer.M 4.80 false) }} + ` (.Printer.M 4.80) }} </dd> <dt>{{ .T "Maximum Change Limit" }}</dt> <dd> @@ -150,7 +150,7 @@ something to purchase, throw in less money than the cost, and then cancel the purchase. Note that most cigarette machines in Austria have a %s max change limit. - ` (.Printer.M 4.90 false) }} + ` (.Printer.M 4.90) }} </p> <p> {{ .T ` |