fix(i18n): align plural fallback with base tags

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 09:33:21 +00:00
parent 04692a185c
commit 1fcfc33d5c
2 changed files with 6 additions and 2 deletions

View file

@ -6,8 +6,7 @@ func GetPluralRule(lang string) PluralRule {
if rule, ok := pluralRules[lang]; ok {
return rule
}
if len(lang) > 2 {
base := lang[:2]
if base := baseLanguageTag(lang); base != "" {
if rule, ok := pluralRules[base]; ok {
return rule
}

View file

@ -85,6 +85,11 @@ func TestGetPluralRule(t *testing.T) {
t.Error("English-US rule(1) should be PluralOne")
}
rule = GetPluralRule("fr-Latn-CA")
if rule(0) != PluralOne {
t.Error("French multi-part tag rule(0) should be PluralOne")
}
rule = GetPluralRule("cy-GB")
if rule(2) != PluralTwo {
t.Error("Welsh-GB rule(2) should be PluralTwo")