-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7de5222
commit 072fa6e
Showing
12 changed files
with
128 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Development notes | ||
|
||
## How to upgrade CLDR data | ||
|
||
1. Go to http://cldr.unicode.org/index/downloads to find the latest version. | ||
1. Download the latest version of cldr-common (e.g. http://unicode.org/Public/cldr/33/cldr-common-33.0.zip) | ||
1. Unzip and copy `common/supplemental/plurals.xml` to `v2/i18n/internal/plural/codegen/plurals.xml` | ||
1. Run `generate.sh` in `v2/i18n/internal/plural/codegen/` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package plural | ||
|
||
import "golang.org/x/text/language" | ||
|
||
// Rules is a set of plural rules by language tag. | ||
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 { | ||
for { | ||
if rule := r[tag]; rule != nil { | ||
return rule | ||
} | ||
tag = tag.Parent() | ||
if tag.IsRoot() { | ||
return nil | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package plural | ||
|
||
import ( | ||
"testing" | ||
|
||
"golang.org/x/text/language" | ||
) | ||
|
||
func TestRules(t *testing.T) { | ||
expectedRule := &Rule{} | ||
|
||
testCases := []struct { | ||
name string | ||
rules Rules | ||
tag language.Tag | ||
rule *Rule | ||
}{ | ||
{ | ||
name: "exact match", | ||
rules: Rules{ | ||
language.English: expectedRule, | ||
language.Spanish: &Rule{}, | ||
}, | ||
tag: language.English, | ||
rule: expectedRule, | ||
}, | ||
{ | ||
name: "inexact match", | ||
rules: Rules{ | ||
language.English: expectedRule, | ||
}, | ||
tag: language.AmericanEnglish, | ||
rule: expectedRule, | ||
}, | ||
{ | ||
name: "portuguese doesn't match european portuguese", | ||
rules: Rules{ | ||
language.EuropeanPortuguese: &Rule{}, | ||
}, | ||
tag: language.Portuguese, | ||
rule: nil, | ||
}, | ||
{ | ||
name: "european portuguese preferred", | ||
rules: Rules{ | ||
language.Portuguese: &Rule{}, | ||
language.EuropeanPortuguese: expectedRule, | ||
}, | ||
tag: language.EuropeanPortuguese, | ||
rule: expectedRule, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
if rule := testCase.rules.Rule(testCase.tag); rule != testCase.rule { | ||
panic(rule) | ||
} | ||
}) | ||
} | ||
} |