fix cookie -- not working

This commit is contained in:
2026-05-12 11:25:32 +02:00
parent 669d24c6a3
commit 8c4e664ca8
23 changed files with 836 additions and 166 deletions
+17
View File
@@ -391,6 +391,9 @@ ORDER BY cl.name ASC
if err := s.db.WithContext(ctx).Raw(strings.TrimSpace(countryQuery), countryArgs...).Scan(&locale.Countries).Error; err != nil {
return HeaderLocaleData{}, err
}
for i := range locale.Countries {
locale.Countries[i] = formatCountryLocaleOption(locale.Countries[i])
}
locale.CurrentLanguage = pickLocaleOptionByID(locale.Languages, languageID)
locale.CurrentCountry = pickLocaleOptionByCode(locale.Countries, countryISO)
@@ -499,3 +502,17 @@ func pickLocaleOptionByCode(options []LocaleOption, code string) LocaleOption {
}
return LocaleOption{Code: code, Label: code, Meta: code}
}
func formatCountryLocaleOption(option LocaleOption) LocaleOption {
label := strings.TrimSpace(option.Label)
currencyCode := strings.TrimSpace(option.Meta)
if idx := strings.IndexByte(currencyCode, ' '); idx >= 0 {
currencyCode = currencyCode[:idx]
}
currencyCode = strings.TrimSpace(currencyCode)
if label == "" || currencyCode == "" {
return option
}
option.Label = label + " " + currencyCode
return option
}
@@ -0,0 +1,26 @@
package catalog
import "testing"
func TestFormatCountryLocaleOptionAddsCurrencyCodeToLabel(t *testing.T) {
option := LocaleOption{
Label: "Polska",
Meta: "PLN zl",
}
got := formatCountryLocaleOption(option)
if got.Label != "Polska PLN" {
t.Fatalf("formatCountryLocaleOption().Label = %q, want %q", got.Label, "Polska PLN")
}
}
func TestFormatCountryLocaleOptionFallsBackWithoutMeta(t *testing.T) {
option := LocaleOption{
Label: "Polska",
}
got := formatCountryLocaleOption(option)
if got.Label != "Polska" {
t.Fatalf("formatCountryLocaleOption().Label = %q, want %q", got.Label, "Polska")
}
}