Skip to content

Commit

Permalink
i18n/language: add Latvian
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr committed Sep 26, 2015
1 parent 5bf37cc commit 5a1679c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Supported languages
* Indonesian (`id`)
* Italian (`it`)
* Korean (`ko`)
* Latvian (`lv`)
* Japanese (`ja`)
* Lithuanian (`lt`)
* Malay (`ms`)
Expand Down
20 changes: 20 additions & 0 deletions i18n/language/pluralspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,26 @@ var pluralSpecs = map[string]*PluralSpec{
},
},

// Latvian
"lv": &PluralSpec{
Plurals: newPluralSet(Zero, One, Other),
PluralFunc: func(ops *operands) Plural {
nMod10 := math.Mod(ops.N, 10)
nMod100 := math.Mod(ops.N, 100)
if nMod10 == 0 ||
(11 <= nMod100 && nMod100 <= 19) ||
(ops.V == 2 && 11 <= ops.F%100 && ops.F%100 <= 19) {
return Zero
}
if (nMod10 == 1 && nMod100 != 11) ||
(ops.V == 2 && ops.F%10 == 1 && ops.F%100 != 11) ||
(ops.V != 2 && ops.F%10 == 1) {
return One
}
return Other
},
},

// Japanese
"ja": &PluralSpec{
Plurals: newPluralSet(Other),
Expand Down
23 changes: 23 additions & 0 deletions i18n/language/pluralspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func TestGetPluralSpec(t *testing.T) {
{"ti", pluralSpecs["ti"]},
{"vi", pluralSpecs["vi"]},
{"vi-VN", pluralSpecs["vi"]},
{"lv", pluralSpecs["lv"]},
{"lv-LV", pluralSpecs["lv"]},
{".en-US..en-US.", nil},
{"zh, en-gb;q=0.8, en;q=0.7", nil},
{"zh,en-gb;q=0.8,en;q=0.7", nil},
Expand Down Expand Up @@ -314,6 +316,27 @@ func TestKorean(t *testing.T) {
runTests(t, "ko", tests)
}

func TestLatvian(t *testing.T) {
tests := []pluralTest{
{0, Zero},
{"0", Zero},
{"0.1", One},
{1, One},
{"1", One},
{onePlusEpsilon, One},
{"10.0", Zero},
{"10.1", One},
{"10.2", Other},
{21, One},
}
tests = appendFloatTests(tests, 0.2, 0.9, Other)
tests = appendFloatTests(tests, 1.2, 1.9, Other)
tests = appendIntTests(tests, 2, 9, Other)
tests = appendIntTests(tests, 10, 20, Zero)
tests = appendIntTests(tests, 22, 29, Other)
runTests(t, "lv", tests)
}

func TestJapanese(t *testing.T) {
tests := appendIntTests(nil, 0, 10, Other)
tests = appendFloatTests(tests, 0, 10, Other)
Expand Down

0 comments on commit 5a1679c

Please sign in to comment.