From 495383f8ba19265518d9cabe802f5e205e9b088b Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Mon, 4 Sep 2023 16:40:20 -0500 Subject: [PATCH] Include 3-letter langs in dump --- cmd/localesdump/main.go | 9 ++++----- localedata/database_test.go | 1 - locales_test.go | 1 - 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/localesdump/main.go b/cmd/localesdump/main.go index 37f9352..8db9f77 100644 --- a/cmd/localesdump/main.go +++ b/cmd/localesdump/main.go @@ -11,12 +11,11 @@ import ( "github.com/nyaruka/go-locales" "github.com/nyaruka/go-locales/localedata" - "github.com/pkg/errors" ) -// matches locale codes in the form xx_XX -var bcp47Regex = regexp.MustCompile(`^[a-z][a-z]_[A-Z][A-Z]$`) +// matches locale codes in the form xx_YY or xxx_YY +var bcp47Regex = regexp.MustCompile(`^[a-z]{2,3}_[A-Z]{2}$`) // data dumped for a single locale type localeDump map[string][]string @@ -107,7 +106,7 @@ func mergeLocales(data map[string]localeDump) map[string]localeDump { distinctByLang := make(map[string][]localeDump, len(data)) for code, dump := range data { - lang := code[:2] + lang := strings.SplitN(code, "_", 2)[0] distinct := true for _, existing := range distinctByLang[lang] { @@ -125,7 +124,7 @@ func mergeLocales(data map[string]localeDump) map[string]localeDump { merged := make(map[string]localeDump, len(data)) for code, dump := range data { - lang := code[:2] + lang := strings.SplitN(code, "_", 2)[0] variesByCountry := len(distinctByLang[lang]) > 1 if variesByCountry { diff --git a/localedata/database_test.go b/localedata/database_test.go index 2e57949..0e9c371 100644 --- a/localedata/database_test.go +++ b/localedata/database_test.go @@ -6,7 +6,6 @@ import ( "github.com/nyaruka/go-locales" "github.com/nyaruka/go-locales/localedata" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/locales_test.go b/locales_test.go index 775f0ec..9dfe41a 100644 --- a/locales_test.go +++ b/locales_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/nyaruka/go-locales" - "github.com/stretchr/testify/assert" )