Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle zh correctly #109

Merged
merged 1 commit into from
May 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions v2/internal/plural/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ type Rules map[language.Tag]*Rule
// Rule returns the closest matching plural rule for the language tag
// or nil if no rule could be found.
func (r Rules) Rule(tag language.Tag) *Rule {
t := tag
for {
if rule := r[tag]; rule != nil {
if rule := r[t]; rule != nil {
return rule
}
tag = tag.Parent()
if tag.IsRoot() {
return nil
t = t.Parent()
if t.IsRoot() {
break
}
}
base, _ := tag.Base()
baseTag, _ := language.Parse(base.String())
return r[baseTag]
}
16 changes: 16 additions & 0 deletions v2/internal/plural/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,22 @@ func TestRules(t *testing.T) {
tag: language.EuropeanPortuguese,
rule: expectedRule,
},
{
name: "zh-Hans",
rules: Rules{
language.Chinese: expectedRule,
},
tag: language.SimplifiedChinese,
rule: expectedRule,
},
{
name: "zh-Hant",
rules: Rules{
language.Chinese: expectedRule,
},
tag: language.TraditionalChinese,
rule: expectedRule,
},
}

for _, testCase := range testCases {
Expand Down