nicksnyder / go-i18n

Translate your Go program into multiple languages.
MIT License
2.98k stars 274 forks source link

Fails to resolve with multiple artificial languages #252

Open bep opened 3 years ago

bep commented 3 years ago
github.com/nicksnyder/go-i18n

The following test fails:

func TestPseudoLanguages(t *testing.T) {
    bundle := NewBundle(language.English)
    bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
    expected := "a3"
    bundle.MustParseMessageFileBytes([]byte(`
hello = "a1"
`), "art-x-a1.toml")
    bundle.MustParseMessageFileBytes([]byte(`
hello = "a2"
`), "art-x-a2.toml")
    bundle.MustParseMessageFileBytes([]byte(`
hello = "a3"
`), "art-x-a3.toml")

    {
        localized, err := NewLocalizer(bundle, "art-x-a3").Localize(&LocalizeConfig{MessageID: "hello"})
        if err != nil {
            t.Fatal(err)
        }
        if localized != expected {
            t.Fatalf("expected %q\ngot %q", expected, localized)
        }
    }
}

I tried to debug this -- looks like it's some odd bug in the upstream x/text Matcher.

https://github.com/gohugoio/hugo/issues/7838

bep commented 3 years ago

I have a patch (almost) ready for this. Will come back with a PR.