package i18n import "testing" func TestSupportedLocalesLoad(t *testing.T) { for _, info := range Supported { cat, ok := catalogs[info.Code] if !ok || len(cat) == 0 { t.Fatalf("locale %q: catalog missing or empty", info.Code) } } } func TestEnglishHasEveryKeyUsedElsewhere(t *testing.T) { // English is the fallback catalog (see T's doc comment), so every // key any other locale defines must also exist in English — a // locale-only key would be silently unreachable from the fallback // path and is almost certainly a typo. en := catalogs[Default] for _, info := range Supported { if info.Code == Default { continue } for key := range catalogs[info.Code] { if _, ok := en[key]; !ok { t.Errorf("locale %q defines key %q that is missing from %q (the fallback catalog)", info.Code, key, Default) } } } } func TestTFallsBackToEnglishThenToKey(t *testing.T) { if got := T("fr", "nav.new_chat"); got != "Nouvelle discussion" { t.Errorf("fr nav.new_chat = %q", got) } // "nav.delete" only exists in a handful of locales' full set; pick // a locale/key combination guaranteed to be English-only to prove // the fallback path, without hard-coding which keys those are. if got := T("es", "billing.quota_exceeded", "Pro", 200); got == "billing.quota_exceeded" { t.Errorf("expected fallback to the English catalog, got the raw key back") } if got := T(Default, "this.key.does.not.exist"); got != "this.key.does.not.exist" { t.Errorf("unknown key should fall back to itself, got %q", got) } } func TestParseLocale(t *testing.T) { if got := ParseLocale("fr"); got != "fr" { t.Errorf("ParseLocale(fr) = %q", got) } if got := ParseLocale("xx-not-a-locale"); got != Default { t.Errorf("ParseLocale(unsupported) = %q, want Default", got) } }