From 2c2f850a29b2e896f640679ed9fcec523ccfdb2d Mon Sep 17 00:00:00 2001
From: Thomas Voss
Date: Sat, 10 Aug 2024 21:32:27 +0200
Subject: Support sorting countries by name
---
templates/base.go | 35 +-
templates/coins_designs.templ | 2 +-
vendor/golang.org/x/text/collate/collate.go | 403 +
vendor/golang.org/x/text/collate/index.go | 32 +
vendor/golang.org/x/text/collate/option.go | 239 +
vendor/golang.org/x/text/collate/sort.go | 81 +
vendor/golang.org/x/text/collate/tables.go | 73789 +++++++++++++++++++
.../golang.org/x/text/internal/colltab/collelem.go | 376 +
.../golang.org/x/text/internal/colltab/colltab.go | 105 +
.../golang.org/x/text/internal/colltab/contract.go | 145 +
vendor/golang.org/x/text/internal/colltab/iter.go | 178 +
.../golang.org/x/text/internal/colltab/numeric.go | 236 +
vendor/golang.org/x/text/internal/colltab/table.go | 275 +
vendor/golang.org/x/text/internal/colltab/trie.go | 159 +
.../golang.org/x/text/internal/colltab/weighter.go | 31 +
vendor/golang.org/x/text/transform/transform.go | 709 +
.../golang.org/x/text/unicode/norm/composition.go | 512 +
vendor/golang.org/x/text/unicode/norm/forminfo.go | 279 +
vendor/golang.org/x/text/unicode/norm/input.go | 109 +
vendor/golang.org/x/text/unicode/norm/iter.go | 458 +
vendor/golang.org/x/text/unicode/norm/normalize.go | 610 +
.../golang.org/x/text/unicode/norm/readwriter.go | 125 +
.../golang.org/x/text/unicode/norm/tables10.0.0.go | 7657 ++
.../golang.org/x/text/unicode/norm/tables11.0.0.go | 7693 ++
.../golang.org/x/text/unicode/norm/tables12.0.0.go | 7710 ++
.../golang.org/x/text/unicode/norm/tables13.0.0.go | 7760 ++
.../golang.org/x/text/unicode/norm/tables15.0.0.go | 7907 ++
.../golang.org/x/text/unicode/norm/tables9.0.0.go | 7637 ++
vendor/golang.org/x/text/unicode/norm/transform.go | 88 +
vendor/golang.org/x/text/unicode/norm/trie.go | 54 +
vendor/modules.txt | 4 +
31 files changed, 125393 insertions(+), 5 deletions(-)
create mode 100644 vendor/golang.org/x/text/collate/collate.go
create mode 100644 vendor/golang.org/x/text/collate/index.go
create mode 100644 vendor/golang.org/x/text/collate/option.go
create mode 100644 vendor/golang.org/x/text/collate/sort.go
create mode 100644 vendor/golang.org/x/text/collate/tables.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/collelem.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/colltab.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/contract.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/iter.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/numeric.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/table.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/trie.go
create mode 100644 vendor/golang.org/x/text/internal/colltab/weighter.go
create mode 100644 vendor/golang.org/x/text/transform/transform.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/composition.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/forminfo.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/input.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/iter.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/normalize.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/readwriter.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/tables10.0.0.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/tables11.0.0.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/tables12.0.0.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/tables13.0.0.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/tables15.0.0.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/tables9.0.0.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/transform.go
create mode 100644 vendor/golang.org/x/text/unicode/norm/trie.go
diff --git a/templates/base.go b/templates/base.go
index ba31baf..76a4da6 100644
--- a/templates/base.go
+++ b/templates/base.go
@@ -2,12 +2,28 @@
package templates
-import "git.thomasvoss.com/euro-cash.eu/i18n"
+import (
+ "fmt"
+ "slices"
-type country struct{ code, name string }
+ "git.thomasvoss.com/euro-cash.eu/i18n"
+ "golang.org/x/text/collate"
+ "golang.org/x/text/language"
+)
-func countries(p i18n.Printer) []country {
- return []country{
+type country struct {
+ code, name string
+}
+
+type sortType int
+
+const (
+ sortByCode sortType = iota
+ sortByName
+)
+
+func countries(p i18n.Printer, sort sortType) []country {
+ xs := []country{
{code: "AD", name: p.T("Andorra")},
{code: "AT", name: p.T("Austria")},
{code: "BE", name: p.T("Belgium")},
@@ -33,4 +49,15 @@ func countries(p i18n.Printer) []country {
{code: "SM", name: p.T("San Marino")},
{code: "VA", name: p.T("Vatican City")},
}
+ switch sort {
+ case sortByCode:
+ case sortByName:
+ c := collate.New(language.MustParse(p.Locale.Bcp))
+ slices.SortFunc(xs, func(x, y country) int {
+ return c.CompareString(x.name, y.name)
+ })
+ default:
+ panic(fmt.Sprintf("Attempted to sort by invalid sortType=%d", sort))
+ }
+ return xs
}
diff --git a/templates/coins_designs.templ b/templates/coins_designs.templ
index 1b1ba6d..6d186e1 100644
--- a/templates/coins_designs.templ
+++ b/templates/coins_designs.templ
@@ -26,7 +26,7 @@ templ CoinsDesigns() {