Skip to content

Commit

Permalink
Include 3-letter langs in dump
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Sep 4, 2023
1 parent 06d0dc0 commit 495383f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
9 changes: 4 additions & 5 deletions cmd/localesdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] {
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion localedata/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 0 additions & 1 deletion locales_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"testing"

"github.com/nyaruka/go-locales"

"github.com/stretchr/testify/assert"
)

Expand Down

0 comments on commit 495383f

Please sign in to comment.