Skip to content

Commit 495383f

Browse files
committed
Include 3-letter langs in dump
1 parent 06d0dc0 commit 495383f

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

cmd/localesdump/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@ import (
1111

1212
"github.com/nyaruka/go-locales"
1313
"github.com/nyaruka/go-locales/localedata"
14-
1514
"github.com/pkg/errors"
1615
)
1716

18-
// matches locale codes in the form xx_XX
19-
var bcp47Regex = regexp.MustCompile(`^[a-z][a-z]_[A-Z][A-Z]$`)
17+
// matches locale codes in the form xx_YY or xxx_YY
18+
var bcp47Regex = regexp.MustCompile(`^[a-z]{2,3}_[A-Z]{2}$`)
2019

2120
// data dumped for a single locale
2221
type localeDump map[string][]string
@@ -107,7 +106,7 @@ func mergeLocales(data map[string]localeDump) map[string]localeDump {
107106
distinctByLang := make(map[string][]localeDump, len(data))
108107

109108
for code, dump := range data {
110-
lang := code[:2]
109+
lang := strings.SplitN(code, "_", 2)[0]
111110
distinct := true
112111

113112
for _, existing := range distinctByLang[lang] {
@@ -125,7 +124,7 @@ func mergeLocales(data map[string]localeDump) map[string]localeDump {
125124
merged := make(map[string]localeDump, len(data))
126125

127126
for code, dump := range data {
128-
lang := code[:2]
127+
lang := strings.SplitN(code, "_", 2)[0]
129128
variesByCountry := len(distinctByLang[lang]) > 1
130129

131130
if variesByCountry {

localedata/database_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/nyaruka/go-locales"
88
"github.com/nyaruka/go-locales/localedata"
9-
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211
)

locales_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
"github.com/nyaruka/go-locales"
7-
87
"github.com/stretchr/testify/assert"
98
)
109

0 commit comments

Comments
 (0)