summaryrefslogtreecommitdiffhomepage
path: root/src/i18n.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/i18n.go')
-rw-r--r--src/i18n.go41
1 files changed, 31 insertions, 10 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)
+}