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",
|
EventName: "Event name",
|
||||||
Footer: "Footer",
|
Footer: "Footer",
|
||||||
CurrencySymbol: "€",
|
CurrencySymbol: "€",
|
||||||
|
Locale: certificateRequest.Locale,
|
||||||
}
|
}
|
||||||
|
|
||||||
result, err := generator.Execute(template, genConfig)
|
result, err := generator.Execute(template, genConfig)
|
||||||
|
@ -37,4 +37,5 @@ type CertificateTemplateOptions struct {
|
|||||||
EventName string `json:"event_name"`
|
EventName string `json:"event_name"`
|
||||||
Footer string `json:"footer"`
|
Footer string `json:"footer"`
|
||||||
CurrencySymbol string `json:"currency_symbol"`
|
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
|
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
|
var formatted string
|
||||||
switch unit {
|
switch unit {
|
||||||
case "kilometer":
|
case "kilometer":
|
||||||
@ -101,7 +101,11 @@ func FormatUnit(unit string, amount int) (string, error) {
|
|||||||
default:
|
default:
|
||||||
return "", errors.New("unknown unit")
|
return "", errors.New("unknown unit")
|
||||||
}
|
}
|
||||||
return strings.Replace(formatted, ".", ",", -1), nil
|
|
||||||
|
if locale == "de" {
|
||||||
|
return strings.Replace(formatted, ".", ",", -1), nil
|
||||||
|
}
|
||||||
|
return formatted, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
func (t *DefaultTemplater) StringToTemplate(templateString string) (*template.Template, error) {
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
{{ .MiddleName }} {{ .LastName }}
|
{{ .MiddleName }} {{ .LastName }}
|
||||||
</p>
|
</p>
|
||||||
<p style="font-size: 1cm; margin-bottom: 0;">hat beim {{ $.EventName }}</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>
|
<p style="font-size: 1cm;">für den guten Zweck zurückgelegt</p>
|
||||||
</main>
|
</main>
|
||||||
<footer class="certificate-footer">
|
<footer class="certificate-footer">
|
||||||
@ -78,15 +78,15 @@
|
|||||||
{{ range .DistanceDonations}}
|
{{ range .DistanceDonations}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
||||||
<td>{{ formatUnit "euro" .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||||
<td>{{ formatUnit "euro" .Amount }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .Amount }} {{ $.CurrencySymbol }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<td>Gesamt</td>
|
<td>Gesamt</td>
|
||||||
<td>{{ formatUnit "euro" .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||||
<td>{{ formatUnit "euro" .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</main>
|
</main>
|
||||||
|
@ -56,7 +56,7 @@
|
|||||||
{{ .MiddleName }} {{ .LastName }}
|
{{ .MiddleName }} {{ .LastName }}
|
||||||
</p>
|
</p>
|
||||||
<p style="font-size: 1cm; margin-bottom: 0;">Ran</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>
|
<p style="font-size: 1cm;">for our good cause at the {{ $.EventName }}</p>
|
||||||
</main>
|
</main>
|
||||||
<footer class="certificate-footer">
|
<footer class="certificate-footer">
|
||||||
@ -78,15 +78,15 @@
|
|||||||
{{ range .DistanceDonations}}
|
{{ range .DistanceDonations}}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
<td>{{ .Donor.FirstName }} {{ .Donor.MiddleName }} {{ .Donor.LastName }}</td>
|
||||||
<td>{{ formatUnit "euro" .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .AmountPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||||
<td>{{ formatUnit "euro" .Amount }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .Amount }} {{ $.CurrencySymbol }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<td>Combined</td>
|
<td>Combined</td>
|
||||||
<td>{{ formatUnit "euro" .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .TotalPerDistance }} {{ $.CurrencySymbol }}</td>
|
||||||
<td>{{ formatUnit "euro" .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
<td>{{ formatUnit "euro" $.Locale .TotalDonations }} {{ $.CurrencySymbol }}</td>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
</main>
|
</main>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user