diff --git a/v2/go.mod b/v2/go.mod index 447a6857..ce404c69 100644 --- a/v2/go.mod +++ b/v2/go.mod @@ -7,3 +7,5 @@ require ( golang.org/x/text v0.3.3 gopkg.in/yaml.v2 v2.3.0 ) + +replace golang.org/x/text => /Users/bep/dev/go/dump/text diff --git a/v2/i18n/bundle_test.go b/v2/i18n/bundle_test.go index 12377899..af5dded7 100644 --- a/v2/i18n/bundle_test.go +++ b/v2/i18n/bundle_test.go @@ -98,6 +98,28 @@ hello = "`+expected+`" } } +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") + + { + localized, err := NewLocalizer(bundle, "art-x-a2").Localize(&LocalizeConfig{MessageID: "hello"}) + if err != nil { + t.Fatal(err) + } + if localized != expected { + t.Fatalf("expected %q\ngot %q", expected, localized) + } + } +} + func TestJSON(t *testing.T) { bundle := NewBundle(language.English) bundle.MustParseMessageFileBytes([]byte(`{ diff --git a/v2/i18n/localizer.go b/v2/i18n/localizer.go index 17261e2e..9ff65163 100644 --- a/v2/i18n/localizer.go +++ b/v2/i18n/localizer.go @@ -171,6 +171,7 @@ func (l *Localizer) LocalizeWithTag(lc *LocalizeConfig) (string, language.Tag, e func (l *Localizer) getMessageTemplate(id string, defaultMessage *Message) (language.Tag, *MessageTemplate, error) { _, i, _ := l.bundle.matcher.Match(l.tags...) + fmt.Println("I", l.tags, l.bundle.tags, i) tag := l.bundle.tags[i] mt := l.bundle.getMessageTemplate(tag, id) if mt != nil {