Skip to content

Commit

Permalink
Fix handling of multiple artificial languages
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Apr 24, 2021
1 parent 482713a commit b3c1841
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions v2/i18n/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(`{
Expand Down
1 change: 1 addition & 0 deletions v2/i18n/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b3c1841

Please sign in to comment.