Skip to content

Commit

Permalink
fix: correct i18n.localize
Browse files Browse the repository at this point in the history
  • Loading branch information
aofei committed Apr 15, 2019
1 parent d89997a commit 080c41c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/tdewolff/minify/v2 v2.3.8
github.com/vmihailenco/msgpack v4.0.4+incompatible
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
golang.org/x/net v0.0.0-20190415100556-4a65cf94b679
golang.org/x/sys v0.0.0-20190415081028-16da32be82c5 // indirect
golang.org/x/text v0.3.0
google.golang.org/appengine v1.5.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a h1:Igim7XhdOpBnWPuYJ70XcN
golang.org/x/crypto v0.0.0-20190411191339-88737f569e3a/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225 h1:kNX+jCowfMYzvlSvJu5pQWEmyWFrBXJ3PBy10xKMXK8=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190415100556-4a65cf94b679 h1:tzVWzOrXxwAwdSCMrf+mbNrZFxwS0+HLP4m2qxtfdhk=
golang.org/x/net v0.0.0-20190415100556-4a65cf94b679/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20181031143558-9b800f95dbbc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqYSEQ0KWqdWLu3xuZJts=
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190415081028-16da32be82c5 h1:UMbOtg4ZL2GyTAolLE9QfNvzskWvFkI935Z98i9moXA=
golang.org/x/sys v0.0.0-20190415081028-16da32be82c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
google.golang.org/appengine v1.5.0 h1:KxkO13IPW4Lslp2bz+KHP2E3gtFlrIGNThxkZQ3g+4c=
Expand Down
8 changes: 5 additions & 3 deletions i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (i *i18n) load() {
}

ts := make([]language.Tag, 0, len(fis))
ls := make(map[string]map[string]string, len(fis))
ls := make(map[string]map[string]string, len(ts))
for _, fi := range fis {
if fi.IsDir() {
continue
Expand Down Expand Up @@ -124,8 +124,10 @@ func (i *i18n) localize(r *Request) {
r.localizedString = func(key string) string {
if v, ok := l[key]; ok {
return v
} else if v, ok := i.locales[i.a.I18nLocaleBase][key]; ok {
return v
} else if l, ok := i.locales[i.a.I18nLocaleBase]; ok {
if v, ok := l[key]; ok {
return v
}
}

return key
Expand Down
14 changes: 0 additions & 14 deletions i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,6 @@ func TestI18nLocalize(t *testing.T) {
assert.NotNil(t, req.localizedString)
assert.Equal(t, "测试", req.LocalizedString("Foobar"))

a = New()
a.I18nLocaleRoot = dir
a.I18nLocaleBase = "foobar"

i = a.i18n

req, _, _ = fakeRRCycle(a, http.MethodGet, "/", nil)

log.SetOutput(ioutil.Discard)
i.localize(req)
log.SetOutput(os.Stderr)

assert.Error(t, i.loadError)

a = New()
i = a.i18n

Expand Down

0 comments on commit 080c41c

Please sign in to comment.