Skip to content

Commit

Permalink
Update to CLDR v46.
Browse files Browse the repository at this point in the history
Bonus change:
Include only "modern" locales in parentLocales.
If a locale is not supported, we don't care what it falls back to.
  • Loading branch information
bojanz committed Nov 1, 2024
1 parent 74ef7fd commit c29e7f7
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Handles currency amounts, provides currency information and formatting.

Powered by CLDR v45, in just ~30kb of data.
Powered by CLDR v46, in just ~40kb of data.

Backstory: https://bojanz.github.io/price-currency-handling-go/

Expand Down
145 changes: 79 additions & 66 deletions data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestFormatter_Format(t *testing.T) {
{"-1234.59", "USD", "", "-$1,234.59"},

// Arabic digits.
{"12345678.90", "USD", "ar", "\u200f١٢٬٣٤٥٬٦٧٨٫٩٠\u00a0US$"},
{"12345678.90", "USD", "ar-EG", "\u200f١٢٬٣٤٥٬٦٧٨٫٩٠\u00a0US$"},
// Arabic extended (Persian) digits.
{"12345678.90", "USD", "fa", "\u200e$۱۲٬۳۴۵٬۶۷۸٫۹۰"},
// Bengali digits.
Expand Down Expand Up @@ -355,7 +355,7 @@ func TestFormatter_Parse(t *testing.T) {
{"1234,00", "EUR", "de-AT", "1234.00"},

// Arabic digits.
{"١٢٬٣٤٥٬٦٧٨٫٩٠\u00a0US$", "USD", "ar", "12345678.90"},
{"١٢٬٣٤٥٬٦٧٨٫٩٠\u00a0US$", "USD", "ar-EG", "12345678.90"},
// Arabic extended (Persian) digits.
{"\u200e$۱۲٬۳۴۵٬۶۷۸٫۹۰", "USD", "fa", "12345678.90"},
// Bengali digits.
Expand Down
14 changes: 6 additions & 8 deletions gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"os/exec"
"reflect"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -207,7 +208,7 @@ func main() {
os.RemoveAll(assetDir)
log.Fatal(err)
}
parentLocales, err := generateParentLocales(assetDir)
parentLocales, err := generateParentLocales(locales, assetDir)
if err != nil {
os.RemoveAll(assetDir)
log.Fatal(err)
Expand Down Expand Up @@ -274,7 +275,7 @@ func main() {
// to parse. See https://github.com/unicode-org/cldr-json for details.
func fetchCLDR(dir string) (string, error) {
repo := "https://github.com/unicode-org/cldr-json.git"
cmd := exec.Command("git", "clone", repo, "--depth", "1", "--branch=45.0.0", dir)
cmd := exec.Command("git", "clone", repo, "--depth", "1", dir)
cmd.Stderr = os.Stderr
_, err := cmd.Output()
if err != nil {
Expand Down Expand Up @@ -772,7 +773,7 @@ func processPattern(pattern string) string {
//
// Ensures ignored locales are skipped.
// Replaces "und" with "en", since this package treats them as equivalent.
func generateParentLocales(dir string) (map[string]string, error) {
func generateParentLocales(locales []string, dir string) (map[string]string, error) {
data, err := os.ReadFile(dir + "/cldr-json/cldr-core/supplemental/parentLocales.json")
if err != nil {
return nil, fmt.Errorf("generateParentLocales: %w", err)
Expand All @@ -794,7 +795,7 @@ func generateParentLocales(dir string) (map[string]string, error) {
if parent == "und" {
parent = "en"
}
if !shouldIgnoreLocale(locale) {
if slices.Contains(locales, locale) && !shouldIgnoreLocale(locale) {
parentLocales[locale] = parent
}
}
Expand All @@ -815,11 +816,8 @@ func shouldIgnoreLocale(locale string) bool {
"be-tarask", "cu", "gv", "prg",
// Valencian differs from its parent only by a single character (è/é).
"ca-ES-valencia",
// Africa secondary languages.
// Not present in "modern" data, just listed in parentLocales.
"bm", "byn", "dje", "dyo", "ff", "ha", "shi", "vai", "wo", "yo",
// Infrequently used locales.
"jv", "kn", "ml", "row", "sat", "sd", "to",
"jv", "kn", "ha", "ml", "sd", "yo",
}
localeParts := strings.Split(locale, "-")
ignore := false
Expand Down

0 comments on commit c29e7f7

Please sign in to comment.