refactor(templater): Format decimals according to locale
This commit is contained in:
parent
eff3354867
commit
f9f30e96c7
@ -51,6 +51,7 @@ func GenerateCertificate(c *fiber.Ctx) error {
|
||||
EventName: "Event name",
|
||||
Footer: "Footer",
|
||||
CurrencySymbol: "€",
|
||||
Locale: certificateRequest.Locale,
|
||||
}
|
||||
|
||||
result, err := generator.Execute(template, genConfig)
|
||||
|
@ -37,4 +37,5 @@ type CertificateTemplateOptions struct {
|
||||
EventName string `json:"event_name"`
|
||||
Footer string `json:"footer"`
|
||||
CurrencySymbol string `json:"currency_symbol"`
|
||||
Locale string `json:"locale"`
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ func (t *DefaultTemplater) SelectSponsorImage(id int) (string, error) {
|
||||
return templates.GetImage(sponsors[id%len(sponsors)]), nil
|
||||
}
|
||||
|
||||
func FormatUnit(unit string, amount int) (string, error) {
|
||||
func FormatUnit(unit string, locale string, amount int) (string, error) {
|
||||
var formatted string
|
||||
switch unit {
|
||||
case "kilometer":
|
||||
@ -101,8 +101,12 @@ func FormatUnit(unit string, amount int) (string, error) {
|
||||
default:
|
||||
return "", errors.New("unknown unit")
|
||||
}
|
||||
|
||||
if locale == "de" {
|
||||
return strings.Replace(formatted, ".", ",", -1), nil
|
||||
}
|
||||
return formatted, nil
|
||||
}
|
||||
|
||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||
return template.New("template").Funcs(template.FuncMap{
|
||||
|
@ -56,7 +56,7 @@
|
||||
{{ .MiddleName }} {{ .LastName }}
|
||||
</p>
|
||||
<p style="font-size: 1cm; margin-bottom: 0;">hat beim {{ $.EventName }}</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" .Distance}}km</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}km</p>
|
||||
<p style="font-size: 1cm;">für den guten Zweck zurückgelegt</p>
|
||||
</main>
|
||||
<footer class="certificate-footer">
|
||||
@ -78,15 +78,15 @@
|
||||
{{ range .DistanceDonations}}
|
||||
<tr>
|
||||
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
||||
<td>{{ formatUnit "euro" .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" .Amount }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .Amount }} {{ $.CurrencySymbol }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<td>Gesamt</td>
|
||||
<td>{{ formatUnit "euro" .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||
</tfoot>
|
||||
</table>
|
||||
</main>
|
||||
|
@ -56,7 +56,7 @@
|
||||
{{ .MiddleName }} {{ .LastName }}
|
||||
</p>
|
||||
<p style="font-size: 1cm; margin-bottom: 0;">Ran</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" .Distance}}km</p>
|
||||
<p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}km</p>
|
||||
<p style="font-size: 1cm;">for our good cause at the {{ $.EventName }}</p>
|
||||
</main>
|
||||
<footer class="certificate-footer">
|
||||
@ -78,15 +78,15 @@
|
||||
{{ range .DistanceDonations}}
|
||||
<tr>
|
||||
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
||||
<td>{{ formatUnit "euro" .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" .Amount }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .Amount }} {{ $.CurrencySymbol }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
<tfoot>
|
||||
<td>Combined</td>
|
||||
<td>{{ formatUnit "euro" .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||
<td>{{ formatUnit "euro" $.Locale .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||
</tfoot>
|
||||
</table>
|
||||
</main>
|
||||
|
Loading…
x
Reference in New Issue
Block a user