Compare commits

..

2 Commits

6 changed files with 119 additions and 8 deletions

View File

@ -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)

View File

@ -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"`
}

View File

@ -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,7 +101,11 @@ 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) {

View File

@ -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>

File diff suppressed because one or more lines are too long

View File

@ -22,6 +22,9 @@ var ContractTemplateDe string
//go:embed certificate/de.html
var CertificateTemplateDe string
//go:embed certificate/en.html
var CertificateTemplateEn string
//go:embed images/sponsoringheader.base64
var ImageSponsoringHeaderBase64 string
@ -47,7 +50,7 @@ func GetTemplate(locale, templateName string) (string, error) {
case "certificate":
switch locale {
case "en":
return ContractTemplateEn, nil
return CertificateTemplateEn, nil
case "de":
return CertificateTemplateDe, nil
}