Skip to content

Commit 4e9a6be

Browse files
committed
i18n several improvements
trigger #1369 Former-commit-id: af16dd8de1a0096d33c4e4c97f29ec12a73302f4
1 parent 377db7f commit 4e9a6be

File tree

5 files changed

+267
-135
lines changed

5 files changed

+267
-135
lines changed

_examples/miscellaneous/i18n/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ var i18nConfig = i18n.Config{
1313
"zh-CN": "./locales/locale_zh-CN.ini", // maps to zh-CN, zh-cn and zh.
1414
},
1515
// Optionals.
16-
Alternatives: map[string]string{ // optional.
17-
"english": "en-US", // now english maps to en-US
18-
"greek": "el-GR", // and greek to el-GR
19-
"chinese": "zh-CN", // and chinese to zh-CN too.
20-
},
16+
// LanguagesMap: i18n.Map{
17+
// "en": "en-US", // now en maps to en-US
18+
// "el": "el-GR",
19+
// "zh": "zh-CN",
20+
// } or a custom i18n.MapFunc, defaults to accept all lowercase and [en] as [en-US] and e.t.c.
2121
URLParameter: "lang",
2222
Subdomain: true,
2323
// Cookie: "lang",

_examples/miscellaneous/i18n/main_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@ import (
1111
func TestI18n(t *testing.T) {
1212
app := newApp()
1313

14-
expectedf := "From the language %s translated output: %s"
14+
const (
15+
expectedf = "From the language %s translated output: %s"
16+
17+
enUS = "hello, iris"
18+
elGR = "γεια, iris"
19+
zhCN = "您好,iris"
20+
)
21+
1522
var (
1623
tests = map[string]string{
17-
"en-US": fmt.Sprintf(expectedf, "en-US", "hello, iris"),
18-
"el-GR": fmt.Sprintf(expectedf, "el-GR", "γεια, iris"),
19-
"zh-CN": fmt.Sprintf(expectedf, "zh-CN", "您好,iris"),
24+
"en-US": fmt.Sprintf(expectedf, "en-US", enUS),
25+
"el-GR": fmt.Sprintf(expectedf, "el-GR", elGR),
26+
"zh-CN": fmt.Sprintf(expectedf, "zh-CN", zhCN),
2027
}
2128

2229
elgrMulti = fmt.Sprintf("From the language: %s, translated output:\n%s=%s\n%s=%s", "el-GR",
@@ -71,4 +78,9 @@ func TestI18n(t *testing.T) {
7178
Body().Equal(elgrMulti)
7279
e.GET("/en/multi").Expect().Status(httptest.StatusOK).
7380
Body().Equal(enusMulti)
81+
82+
e.GET("/el-GRtemplates").Expect().Status(httptest.StatusNotFound)
83+
e.GET("/el-templates").Expect().Status(httptest.StatusNotFound)
84+
85+
e.GET("/el/templates").Expect().Status(httptest.StatusOK).Body().Contains(elGR).Contains(zhCN)
7486
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ require (
1919
github.com/hashicorp/go-version v1.2.0 // indirect
2020
github.com/iris-contrib/blackfriday v2.0.0+incompatible
2121
github.com/iris-contrib/go.uuid v2.0.0+incompatible
22-
github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0
2322
github.com/iris-contrib/schema v0.0.1
2423
github.com/json-iterator/go v1.1.6
2524
github.com/kataras/golog v0.0.9
@@ -32,5 +31,6 @@ require (
3231
github.com/ryanuber/columnize v2.1.0+incompatible
3332
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
3433
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
34+
gopkg.in/ini.v1 v1.51.0
3535
gopkg.in/yaml.v2 v2.2.2
3636
)

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ github.com/iris-contrib/blackfriday v2.0.0+incompatible h1:o5sHQHHm0ToHUlAJSTjW9
4646
github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
4747
github.com/iris-contrib/go.uuid v2.0.0+incompatible h1:XZubAYg61/JwnJNbZilGjf3b3pB80+OQg2qf6c8BfWE=
4848
github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
49-
github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI=
5049
github.com/iris-contrib/schema v0.0.1 h1:10g/WnoRR+U+XXHWKBHeNy/+tZmM2kcAVGLOsz+yaDA=
5150
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
5251
github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs=
@@ -116,6 +115,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
116115
golang.org/x/tools v0.0.0-20181221001348-537d06c36207/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
117116
golang.org/x/tools v0.0.0-20190327201419-c70d86f8b7cf/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
118117
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
118+
gopkg.in/ini.v1 v1.51.0 h1:AQvPpx3LzTDM0AjnIRlVFwFFGC+npRopjZxLJj6gdno=
119+
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
119120
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA=
120121
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
121122
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)