1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
package i18n
import (
"fmt"
"strings"
"time"
"golang.org/x/text/language"
"golang.org/x/text/message"
)
//go:generate gotext -srclang=en-GB update -out=catalog.go -lang=en-GB,nl-NL git.thomasvoss.com/euro-cash.eu
type Printer struct {
Locale Locale
printer *message.Printer
}
type Locale struct {
Code string
Name string
dateFmt string
moneyFmt string
Eurozone bool
Enabled bool
}
var (
Locales = [...]Locale{
Locale{
Code: "ca-AD",
Name: "català",
dateFmt: "2/1/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "de-DE",
Name: "Deutsch",
dateFmt: "2.1.2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "el-GR",
Name: "ελληνικά",
dateFmt: "2/1/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "en-GB",
Name: "English",
dateFmt: "02/01/2006",
Eurozone: true,
Enabled: true,
},
Locale{
Code: "es-ES",
Name: "español",
dateFmt: "2/1/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "et-EE",
Name: "eesti",
dateFmt: "2.1.2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "fi-FI",
Name: "suomi",
dateFmt: "2.1.2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "fr-FR",
Name: "français",
dateFmt: "02/01/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "ga-IE",
Name: "Gaeilge",
dateFmt: "02/01/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "hr-HR",
Name: "hrvatski",
dateFmt: "02. 01. 2006.",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "it-IT",
Name: "italiano",
dateFmt: "02/01/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "lb-LU",
Name: "lëtzebuergesch",
dateFmt: "2.1.2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "lt-LT",
Name: "lietuvių",
dateFmt: "2006-01-02",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "lv-LV",
Name: "latviešu",
dateFmt: "2.01.2006.",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "mt-MT",
Name: "Malti",
dateFmt: "2/1/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "nl-NL",
Name: "Nederlands",
dateFmt: "2-1-2006",
Eurozone: true,
Enabled: true,
},
Locale{
Code: "pt-PT",
Name: "português",
dateFmt: "02/01/2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "sk-SK",
Name: "slovenčina",
dateFmt: "2. 1. 2006",
Eurozone: true,
Enabled: false,
},
Locale{
Code: "sl-SI",
Name: "slovenščina",
dateFmt: "2. 1. 2006",
Eurozone: true,
Enabled: false,
},
/* Non-Eurozone locales */
Locale{
Code: "bg-BG",
Name: "български",
dateFmt: "2.01.2006 г.",
Eurozone: false,
Enabled: false,
},
Locale{
Code: "en-US",
Name: "English (US)",
dateFmt: "1/2/2006",
Eurozone: false,
Enabled: false,
},
Locale{
Code: "ro-RO",
Name: "română",
dateFmt: "02.01.2006",
Eurozone: false,
Enabled: false,
},
Locale{
Code: "uk-UA",
Name: "yкраїнська",
dateFmt: "02.01.2006",
Eurozone: false,
Enabled: false,
},
}
/* Map of language codes to printers. We do this instead of just
using language.MustParse() directly so that we can easily see if a
language is supported or not. */
Printers map[string]Printer = make(map[string]Printer, len(Locales))
DefaultPrinter Printer
)
func InitPrinters() {
for _, loc := range Locales {
if loc.Enabled {
lang := language.MustParse(loc.Code)
Printers[strings.ToLower(loc.Code)] = Printer{
Locale: loc,
printer: message.NewPrinter(lang),
}
}
}
DefaultPrinter = Printers["en-gb"]
}
func (p Printer) T(fmt string, args ...any) string {
return p.printer.Sprintf(fmt, args...)
}
func (p Printer) Date(d time.Time) string {
return d.Format(p.Locale.dateFmt)
}
/* TODO: Try to use a decimal type here */
func (p Printer) Money(val float64, round bool) string {
var valstr string
/* Hack to avoid gotext writing these two ‘translations’ into the
translations file */
f := p.printer.Sprintf
if round {
valstr = f("%d", int(val))
} else {
valstr = f("%.2f", val)
}
/* All Eurozone languages place the eurosign after the value except
for Dutch, English, Gaelic, and Maltese. Austrian German also
uses Dutch-style formatting, but we do not support that dialect. */
switch p.Locale.Code {
case "en-GB", "en-US", "ga-IE", "mt-MT":
return fmt.Sprintf("€%s", valstr)
case "nl-NL":
return fmt.Sprintf("€ %s", valstr)
default:
return fmt.Sprintf("%s €", valstr)
}
}
func (l Locale) Language() string {
return l.Code[:2]
}
|