go-i18n icon indicating copy to clipboard operation
go-i18n copied to clipboard

Fails to resolve with multiple artificial languages

Open bep opened this issue 3 years ago • 1 comments

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 avatar Apr 23 '21 07:04 bep

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

bep avatar Apr 24 '21 17:04 bep