2 Commits
1.6.2 ... 1.7.1

Author SHA1 Message Date
ac471b28a6 fix(services/templater): Update kilometer formatting to include dynamic separator based on locale
All checks were successful
Build release images / build-container (push) Successful in 4m8s
Build latest image / build-container (push) Successful in 4m14s
2025-05-27 16:51:09 +02:00
76d982fa04 fix(templates/certificates): Remove 'km' suffix from formatted distance output and calculate the suffix dynamicly
All checks were successful
Build release images / build-container (push) Successful in 3m49s
Build latest image / build-container (push) Successful in 4m9s
2025-05-26 16:59:42 +02:00
3 changed files with 19 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"html/template" "html/template"
"math"
"strings" "strings"
"go.uber.org/zap" "go.uber.org/zap"
@@ -89,9 +90,24 @@ func (t *DefaultTemplater) LoadImage(name string) (string, error) {
func (t *DefaultTemplater) FormatUnit(unit string, locale string, amount int) (string, error) { func (t *DefaultTemplater) FormatUnit(unit string, locale string, amount int) (string, error) {
var formatted string var formatted string
var seperator string
switch locale {
case "de":
seperator = " "
default:
seperator = ""
}
switch unit { switch unit {
case "kilometer": case "kilometer":
formatted = fmt.Sprintf("%.3f", float64(amount)/1000) if amount < 1000 {
formatted = fmt.Sprintf("%d%sm", amount, seperator)
} else if (amount % 1000) == 0 {
formatted = fmt.Sprintf("%d%skm", amount/1000, seperator)
} else {
kilometers := math.Floor(float64(amount) / 1000)
meters := amount - int(kilometers)*1000
formatted = fmt.Sprintf("%d%skm %d%sm", int(kilometers), seperator, meters, seperator)
}
case "euro": case "euro":
formatted = fmt.Sprintf("%.2f", float64(amount)/100) formatted = fmt.Sprintf("%.2f", float64(amount)/100)
default: default:

View File

@@ -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" $.Locale .Distance}}km</p> <p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}</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">

View File

@@ -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" $.Locale .Distance}}km</p> <p style="font-size: 2cm; font-weight: bold; margin-bottom: 0;">{{formatUnit "kilometer" $.Locale .Distance}}</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">