Skip to content

Commit

Permalink
Export GetPluralSpec
Browse files Browse the repository at this point in the history
This is a follow up to this long-lived Hugo issue:

gohugoio/hugo#3564

This may be improved on in nicksnyder#82 -- but this one is needed just go get it done.

The plan for Hugo's part is:

For all the language codes in use:

1. Check if it is already registered (`GetPluralSpec`)
2. If not, register it as an alias to `GetPluralSpec("en")`
  • Loading branch information
bep committed Nov 5, 2017
1 parent ca33e78 commit f6f0d9c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions i18n/language/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ func Parse(src string) []*Language {
switch chr {
case ',', ';', '.':
tag := strings.TrimSpace(src[start:end])
if spec := getPluralSpec(tag); spec != nil {
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
start = end + 1
}
}
if start > 0 {
tag := strings.TrimSpace(src[start:])
if spec := getPluralSpec(tag); spec != nil {
if spec := GetPluralSpec(tag); spec != nil {
langs = append(langs, &Language{NormalizeTag(tag), spec})
}
return dedupe(langs)
}
if spec := getPluralSpec(src); spec != nil {
if spec := GetPluralSpec(src); spec != nil {
langs = append(langs, &Language{NormalizeTag(src), spec})
}
return langs
Expand Down
4 changes: 2 additions & 2 deletions i18n/language/pluralspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func (ps *PluralSpec) Plural(number interface{}) (Plural, error) {
return ps.PluralFunc(ops), nil
}

// getPluralSpec returns the PluralSpec that matches the longest prefix of tag.
// GetPluralSpec returns the PluralSpec that matches the longest prefix of tag.
// It returns nil if no PluralSpec matches tag.
func getPluralSpec(tag string) *PluralSpec {
func GetPluralSpec(tag string) *PluralSpec {
tag = NormalizeTag(tag)
subtag := tag
for {
Expand Down
2 changes: 1 addition & 1 deletion i18n/language/pluralspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestGetPluralSpec(t *testing.T) {
{"xx", nil},
}
for _, test := range tests {
spec := getPluralSpec(test.src)
spec := GetPluralSpec(test.src)
if spec != test.spec {
t.Errorf("getPluralSpec(%q) = %q expected %q", test.src, spec, test.spec)
}
Expand Down

0 comments on commit f6f0d9c

Please sign in to comment.