Skip to content

Commit

Permalink
Update CLDR version to v44 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorlif committed Nov 28, 2023
1 parent bf7e2f1 commit 0d39365
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Spreak ![Test status](https://github.com/vorlif/spreak/workflows/Test/badge.svg) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![PkgGoDev](https://pkg.go.dev/badge/github.com/vorlif/spreak)](https://pkg.go.dev/github.com/vorlif/spreak) [![Go Report Card](https://goreportcard.com/badge/github.com/vorlif/spreak)](https://goreportcard.com/report/github.com/vorlif/spreak) [![codecov](https://codecov.io/gh/vorlif/spreak/branch/main/graph/badge.svg?token=N1O0ZE1OFW)](https://codecov.io/gh/vorlif/spreak) ![MinVersion](https://img.shields.io/badge/Go-1.17+-blue)
# Spreak ![Test status](https://github.com/vorlif/spreak/workflows/Test/badge.svg) [![MIT license](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE) [![PkgGoDev](https://pkg.go.dev/badge/github.com/vorlif/spreak)](https://pkg.go.dev/github.com/vorlif/spreak) [![Go Report Card](https://goreportcard.com/badge/github.com/vorlif/spreak)](https://goreportcard.com/report/github.com/vorlif/spreak) [![codecov](https://codecov.io/gh/vorlif/spreak/branch/main/graph/badge.svg?token=N1O0ZE1OFW)](https://codecov.io/gh/vorlif/spreak) ![MinVersion](https://img.shields.io/badge/Go-1.19+-blue)

Flexible translation and humanization library for Go, based on the concepts behind gettext. Requires Go 1.19+.

Expand All @@ -21,7 +21,7 @@ I wanted to solve these problems for myself, and so spreak was born.
(with **support for templates**)
* [Support](https://pkg.go.dev/github.com/vorlif/spreak#hdr-Plurals)
for [gettext](https://www.gnu.org/software/gettext/manual/html_node/Plural-forms.html)
and [CLDR v42](https://cldr.unicode.org/index/cldr-spec/plural-rules) plural rules.
and [CLDR v44](https://cldr.unicode.org/index/cldr-spec/plural-rules) plural rules.
* Support of bilingual and monolingual formats

### Usage
Expand Down
18 changes: 18 additions & 0 deletions catalog/cldrplural/builtin_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ func init() {
},
})

addRuleSet([]string{"blo"}, &RuleSet{
Categories: newCategories(Zero, One, Other),
FormFunc: func(ops *Operands) Category {

// n = 0
if ops.N == 0 {
return Zero
}

// n = 1
if ops.N == 1 {
return One
}

return Other
},
})

addRuleSet([]string{"bs", "hr", "sh", "sr"}, &RuleSet{
Categories: newCategories(One, Few, Other),
FormFunc: func(ops *Operands) Category {
Expand Down
23 changes: 23 additions & 0 deletions catalog/cldrplural/builtin_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,29 @@ func TestBuiltinTzm(t *testing.T) {
}
}

func TestBuiltinBlo(t *testing.T) {
for _, lang := range []string{"blo"} {
set, found := builtInRuleSets[language.MustParse(lang).String()]
require.True(t, found)

for _, sample := range []string{"0", "0.0", "0.00", "0.000", "0.0000"} {
op := MustNewOperands(sample)
assert.Equal(t, Zero, set.FormFunc(op))
}

for _, sample := range []string{"1", "1.0", "1.00", "1.000", "1.0000"} {
op := MustNewOperands(sample)
assert.Equal(t, One, set.FormFunc(op))
}

for _, sample := range []string{"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "100", "1000", "10000", "100000", "1000000", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"} {
op := MustNewOperands(sample)
assert.Equal(t, Other, set.FormFunc(op))
}

}
}

func TestBuiltinBsHrShSr(t *testing.T) {
for _, lang := range []string{"bs", "hr", "sh", "sr"} {
set, found := builtInRuleSets[language.MustParse(lang).String()]
Expand Down
26 changes: 26 additions & 0 deletions catalog/cldrplural/evaluation_gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,32 @@ func TestEvaluateTzm(t *testing.T) {

}

func TestEvaluateBlo(t *testing.T) {
var rule *ast.Rule

rule = ast.MustParse("n = 0 @integer 0 @decimal 0.0, 0.00, 0.000, 0.0000")

for _, sample := range []string{"0", "0.0", "0.00", "0.000", "0.0000"} {
op := MustNewOperands(sample)
assert.True(t, evaluate(rule, op), sample)
}

rule = ast.MustParse("n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000")

for _, sample := range []string{"1", "1.0", "1.00", "1.000", "1.0000"} {
op := MustNewOperands(sample)
assert.True(t, evaluate(rule, op), sample)
}

rule = ast.MustParse(" @integer 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 2.0~2.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …")

for _, sample := range []string{"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "100", "1000", "10000", "100000", "1000000", "2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"} {
op := MustNewOperands(sample)
assert.True(t, evaluate(rule, op), sample)
}

}

func TestEvaluateBsHrShSr(t *testing.T) {
var rule *ast.Rule

Expand Down

0 comments on commit 0d39365

Please sign in to comment.