diff --git a/i18n/language/codegen/main.go b/i18n/language/codegen/main.go index 5d6b6ad4..58971033 100644 --- a/i18n/language/codegen/main.go +++ b/i18n/language/codegen/main.go @@ -81,9 +81,9 @@ var codeTemplate = template.Must(template.New("spec").Parse(`package language func init() { {{range .PluralGroups}} - registerPluralSpec({{printf "%#v" .SplitLocales}}, &PluralSpec{ + RegisterPluralSpec({{printf "%#v" .SplitLocales}}, &PluralSpec{ Plurals: newPluralSet({{range $i, $e := .PluralRules}}{{if $i}}, {{end}}{{$e.CountTitle}}{{end}}), - PluralFunc: func(ops *operands) Plural { {{range .PluralRules}}{{if .GoCondition}} + PluralFunc: func(ops *Operands) Plural { {{range .PluralRules}}{{if .GoCondition}} // {{.Condition}} if {{.GoCondition}} { return {{.CountTitle}} diff --git a/i18n/language/codegen/plurals.xml b/i18n/language/codegen/plurals.xml index cdd0b529..3310c8ee 100644 --- a/i18n/language/codegen/plurals.xml +++ b/i18n/language/codegen/plurals.xml @@ -6,13 +6,13 @@ CLDR data files are interpreted according to the LDML specification (http://unic For terms of use, see http://www.unicode.org/copyright.html --> - + - + @integer 0~15, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … @@ -26,6 +26,10 @@ For terms of use, see http://www.unicode.org/copyright.html i = 0,1 @integer 0, 1 @decimal 0.0~1.5 @integer 2~17, 100, 1000, 10000, 100000, 1000000, … @decimal 2.0~3.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … + + i = 0..1 @integer 0, 1 @decimal 0.0~1.5 + @integer 2~17, 100, 1000, 10000, 100000, 1000000, … @decimal 2.0~3.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … + i = 1 and v = 0 @integer 1 @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … @@ -42,18 +46,10 @@ For terms of use, see http://www.unicode.org/copyright.html n = 0..1 or n = 11..99 @integer 0, 1, 11~24 @decimal 0.0, 1.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0 @integer 2~10, 100~106, 1000, 10000, 100000, 1000000, … @decimal 0.1~0.9, 1.1~1.7, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … - - n = 0..2 and n != 2 @integer 0, 1 @decimal 0.0, 1.0, 0.00, 1.00, 0.000, 1.000, 0.0000, 1.0000 - @integer 2~17, 100, 1000, 10000, 100000, 1000000, … @decimal 0.1~0.9, 1.1~1.7, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … - n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000 @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~0.9, 1.1~1.6, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … - - n = 1 and v = 0 @integer 1 - @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … - n = 1 or t != 0 and i = 0,1 @integer 1 @decimal 0.1~1.6 @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0, 2.0~3.4, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, … @@ -210,7 +206,7 @@ For terms of use, see http://www.unicode.org/copyright.html - + n = 0 @integer 0 @decimal 0.0, 0.00, 0.000, 0.0000 n = 1 @integer 1 @decimal 1.0, 1.00, 1.000, 1.0000 n = 2 @integer 2 @decimal 2.0, 2.00, 2.000, 2.0000 diff --git a/i18n/language/language_test.go b/i18n/language/language_test.go index 2949bfe4..1ab3314d 100644 --- a/i18n/language/language_test.go +++ b/i18n/language/language_test.go @@ -18,8 +18,8 @@ func TestParse(t *testing.T) { {"zh-TW", []*Language{{"zh-tw", pluralSpecs["zh"]}}}, {"pt-BR", []*Language{{"pt-br", pluralSpecs["pt"]}}}, {"pt_BR", []*Language{{"pt-br", pluralSpecs["pt"]}}}, - {"pt-PT", []*Language{{"pt-pt", pluralSpecs["pt-pt"]}}}, - {"pt_PT", []*Language{{"pt-pt", pluralSpecs["pt-pt"]}}}, + {"pt-PT", []*Language{{"pt-pt", pluralSpecs["pt"]}}}, + {"pt_PT", []*Language{{"pt-pt", pluralSpecs["pt"]}}}, {"zh-Hans-CN", []*Language{{"zh-hans-cn", pluralSpecs["zh"]}}}, {"zh-Hant-TW", []*Language{{"zh-hant-tw", pluralSpecs["zh"]}}}, {"en-US-en-US", []*Language{{"en-us-en-us", pluralSpecs["en"]}}}, diff --git a/i18n/language/pluralspec_gen.go b/i18n/language/pluralspec_gen.go index 925a90d9..0268bb92 100644 --- a/i18n/language/pluralspec_gen.go +++ b/i18n/language/pluralspec_gen.go @@ -4,7 +4,7 @@ package language func init() { - RegisterPluralSpec([]string{"bm", "bo", "dz", "id", "ig", "ii", "in", "ja", "jbo", "jv", "jw", "kde", "kea", "km", "ko", "lkt", "lo", "ms", "my", "nqo", "root", "sah", "ses", "sg", "th", "to", "vi", "wo", "yo", "zh"}, &PluralSpec{ + RegisterPluralSpec([]string{"bm", "bo", "dz", "id", "ig", "ii", "in", "ja", "jbo", "jv", "jw", "kde", "kea", "km", "ko", "lkt", "lo", "ms", "my", "nqo", "root", "sah", "ses", "sg", "th", "to", "vi", "wo", "yo", "yue", "zh"}, &PluralSpec{ Plurals: newPluralSet(Other), PluralFunc: func(ops *Operands) Plural { return Other @@ -31,6 +31,16 @@ func init() { return Other }, }) + RegisterPluralSpec([]string{"pt"}, &PluralSpec{ + Plurals: newPluralSet(One, Other), + PluralFunc: func(ops *Operands) Plural { + // i = 0..1 + if intInRange(ops.I, 0, 1) { + return One + } + return Other + }, + }) RegisterPluralSpec([]string{"ast", "ca", "de", "en", "et", "fi", "fy", "gl", "it", "ji", "nl", "sv", "sw", "ur", "yi"}, &PluralSpec{ Plurals: newPluralSet(One, Other), PluralFunc: func(ops *Operands) Plural { @@ -73,16 +83,6 @@ func init() { return Other }, }) - RegisterPluralSpec([]string{"pt"}, &PluralSpec{ - Plurals: newPluralSet(One, Other), - PluralFunc: func(ops *Operands) Plural { - // n = 0..2 and n != 2 - if ops.NinRange(0, 2) && !ops.NequalsAny(2) { - return One - } - return Other - }, - }) RegisterPluralSpec([]string{"af", "asa", "az", "bem", "bez", "bg", "brx", "ce", "cgg", "chr", "ckb", "dv", "ee", "el", "eo", "es", "eu", "fo", "fur", "gsw", "ha", "haw", "hu", "jgo", "jmc", "ka", "kaj", "kcg", "kk", "kkj", "kl", "ks", "ksb", "ku", "ky", "lb", "lg", "mas", "mgo", "ml", "mn", "nah", "nb", "nd", "ne", "nn", "nnh", "no", "nr", "ny", "nyn", "om", "or", "os", "pap", "ps", "rm", "rof", "rwk", "saq", "sdh", "seh", "sn", "so", "sq", "ss", "ssy", "st", "syr", "ta", "te", "teo", "tig", "tk", "tn", "tr", "ts", "ug", "uz", "ve", "vo", "vun", "wae", "xh", "xog"}, &PluralSpec{ Plurals: newPluralSet(One, Other), PluralFunc: func(ops *Operands) Plural { @@ -93,16 +93,6 @@ func init() { return Other }, }) - RegisterPluralSpec([]string{"pt_PT"}, &PluralSpec{ - Plurals: newPluralSet(One, Other), - PluralFunc: func(ops *Operands) Plural { - // n = 1 and v = 0 - if ops.NequalsAny(1) && intEqualsAny(ops.V, 0) { - return One - } - return Other - }, - }) RegisterPluralSpec([]string{"da"}, &PluralSpec{ Plurals: newPluralSet(One, Other), PluralFunc: func(ops *Operands) Plural { @@ -512,7 +502,7 @@ func init() { return Other }, }) - RegisterPluralSpec([]string{"ar"}, &PluralSpec{ + RegisterPluralSpec([]string{"ar", "ars"}, &PluralSpec{ Plurals: newPluralSet(Zero, One, Two, Few, Many, Other), PluralFunc: func(ops *Operands) Plural { // n = 0 diff --git a/i18n/language/pluralspec_gen_test.go b/i18n/language/pluralspec_gen_test.go index c8ec41fd..4cfa97bd 100644 --- a/i18n/language/pluralspec_gen_test.go +++ b/i18n/language/pluralspec_gen_test.go @@ -4,13 +4,13 @@ package language import "testing" -func TestBmBoDzIdIgIiInJaJboJvJwKdeKeaKmKoLktLoMsMyNqoRootSahSesSgThToViWoYoZh(t *testing.T) { +func TestBmBoDzIdIgIiInJaJboJvJwKdeKeaKmKoLktLoMsMyNqoRootSahSesSgThToViWoYoYueZh(t *testing.T) { var tests []pluralTest tests = appendIntegerTests(tests, Other, []string{"0~15", "100", "1000", "10000", "100000", "1000000"}) tests = appendDecimalTests(tests, Other, []string{"0.0~1.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"}) - locales := []string{"bm", "bo", "dz", "id", "ig", "ii", "in", "ja", "jbo", "jv", "jw", "kde", "kea", "km", "ko", "lkt", "lo", "ms", "my", "nqo", "root", "sah", "ses", "sg", "th", "to", "vi", "wo", "yo", "zh"} + locales := []string{"bm", "bo", "dz", "id", "ig", "ii", "in", "ja", "jbo", "jv", "jw", "kde", "kea", "km", "ko", "lkt", "lo", "ms", "my", "nqo", "root", "sah", "ses", "sg", "th", "to", "vi", "wo", "yo", "yue", "zh"} for _, locale := range locales { runTests(t, locale, tests) } @@ -46,6 +46,21 @@ func TestFfFrHyKab(t *testing.T) { } } +func TestPt(t *testing.T) { + var tests []pluralTest + + tests = appendIntegerTests(tests, One, []string{"0", "1"}) + tests = appendDecimalTests(tests, One, []string{"0.0~1.5"}) + + tests = appendIntegerTests(tests, Other, []string{"2~17", "100", "1000", "10000", "100000", "1000000"}) + tests = appendDecimalTests(tests, Other, []string{"2.0~3.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"}) + + locales := []string{"pt"} + for _, locale := range locales { + runTests(t, locale, tests) + } +} + func TestAstCaDeEnEtFiFyGlItJiNlSvSwUrYi(t *testing.T) { var tests []pluralTest @@ -105,21 +120,6 @@ func TestTzm(t *testing.T) { } } -func TestPt(t *testing.T) { - var tests []pluralTest - - tests = appendIntegerTests(tests, One, []string{"0", "1"}) - tests = appendDecimalTests(tests, One, []string{"0.0", "1.0", "0.00", "1.00", "0.000", "1.000", "0.0000", "1.0000"}) - - tests = appendIntegerTests(tests, Other, []string{"2~17", "100", "1000", "10000", "100000", "1000000"}) - tests = appendDecimalTests(tests, Other, []string{"0.1~0.9", "1.1~1.7", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"}) - - locales := []string{"pt"} - for _, locale := range locales { - runTests(t, locale, tests) - } -} - func TestAfAsaAzBemBezBgBrxCeCggChrCkbDvEeElEoEsEuFoFurGswHaHawHuJgoJmcKaKajKcgKkKkjKlKsKsbKuKyLbLgMasMgoMlMnNahNbNdNeNnNnhNoNrNyNynOmOrOsPapPsRmRofRwkSaqSdhSehSnSoSqSsSsyStSyrTaTeTeoTigTkTnTrTsUgUzVeVoVunWaeXhXog(t *testing.T) { var tests []pluralTest @@ -135,20 +135,6 @@ func TestAfAsaAzBemBezBgBrxCeCggChrCkbDvEeElEoEsEuFoFurGswHaHawHuJgoJmcKaKajKcgK } } -func TestPt_PT(t *testing.T) { - var tests []pluralTest - - tests = appendIntegerTests(tests, One, []string{"1"}) - - tests = appendIntegerTests(tests, Other, []string{"0", "2~16", "100", "1000", "10000", "100000", "1000000"}) - tests = appendDecimalTests(tests, Other, []string{"0.0~1.5", "10.0", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"}) - - locales := []string{"pt_PT"} - for _, locale := range locales { - runTests(t, locale, tests) - } -} - func TestDa(t *testing.T) { var tests []pluralTest @@ -590,7 +576,7 @@ func TestGv(t *testing.T) { } } -func TestAr(t *testing.T) { +func TestArArs(t *testing.T) { var tests []pluralTest tests = appendIntegerTests(tests, Zero, []string{"0"}) @@ -611,7 +597,7 @@ func TestAr(t *testing.T) { tests = appendIntegerTests(tests, Other, []string{"100~102", "200~202", "300~302", "400~402", "500~502", "600", "1000", "10000", "100000", "1000000"}) tests = appendDecimalTests(tests, Other, []string{"0.1~0.9", "1.1~1.7", "10.1", "100.0", "1000.0", "10000.0", "100000.0", "1000000.0"}) - locales := []string{"ar"} + locales := []string{"ar", "ars"} for _, locale := range locales { runTests(t, locale, tests) } diff --git a/i18n/language/pluralspec_test.go b/i18n/language/pluralspec_test.go index 34931b7b..919b489b 100644 --- a/i18n/language/pluralspec_test.go +++ b/i18n/language/pluralspec_test.go @@ -23,8 +23,8 @@ func TestGetPluralSpec(t *testing.T) { {"zh-TW", pluralSpecs["zh"]}, {"pt-BR", pluralSpecs["pt"]}, {"pt_BR", pluralSpecs["pt"]}, - {"pt-PT", pluralSpecs["pt-pt"]}, - {"pt_PT", pluralSpecs["pt-pt"]}, + {"pt-PT", pluralSpecs["pt"]}, + {"pt_PT", pluralSpecs["pt"]}, {"zh-Hans-CN", pluralSpecs["zh"]}, {"zh-Hant-TW", pluralSpecs["zh"]}, {"zh-CN", pluralSpecs["zh"]}, @@ -462,11 +462,11 @@ func TestPortuguese(t *testing.T) { {"0.0", One}, {1, One}, {"1.0", One}, - {onePlusEpsilon, Other}, + {onePlusEpsilon, One}, {2, Other}, } - tests = appendFloatTests(tests, 0.1, 0.9, Other) - tests = appendFloatTests(tests, 1.1, 10.0, Other) + tests = appendFloatTests(tests, 0, 1.5, One) + tests = appendFloatTests(tests, 2, 10.0, Other) runTests(t, "pt", tests) } @@ -484,23 +484,6 @@ func TestMacedonian(t *testing.T) { runTests(t, "mk", tests) } -func TestPortugueseEuropean(t *testing.T) { - tests := []pluralTest{ - {0, Other}, - {"0.0", Other}, - {"0.1", Other}, - {"0.01", Other}, - {1, One}, - {"1", One}, - {"1.1", Other}, - {"1.01", Other}, - {onePlusEpsilon, Other}, - {2, Other}, - } - tests = appendFloatTests(tests, 2.0, 10.0, Other) - runTests(t, "pt-pt", tests) -} - func TestRussian(t *testing.T) { tests := []pluralTest{ {0, Many},