1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-05 11:17:03 +00:00

i18n several improvements

trigger #1369


Former-commit-id: af16dd8de1a0096d33c4e4c97f29ec12a73302f4
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-11-22 02:57:26 +02:00
parent 377db7f822
commit 4e9a6be9aa
5 changed files with 273 additions and 141 deletions

View File

@@ -13,11 +13,11 @@ var i18nConfig = i18n.Config{
"zh-CN": "./locales/locale_zh-CN.ini", // maps to zh-CN, zh-cn and zh.
},
// Optionals.
Alternatives: map[string]string{ // optional.
"english": "en-US", // now english maps to en-US
"greek": "el-GR", // and greek to el-GR
"chinese": "zh-CN", // and chinese to zh-CN too.
},
// LanguagesMap: i18n.Map{
// "en": "en-US", // now en maps to en-US
// "el": "el-GR",
// "zh": "zh-CN",
// } or a custom i18n.MapFunc, defaults to accept all lowercase and [en] as [en-US] and e.t.c.
URLParameter: "lang",
Subdomain: true,
// Cookie: "lang",

View File

@@ -11,12 +11,19 @@ import (
func TestI18n(t *testing.T) {
app := newApp()
expectedf := "From the language %s translated output: %s"
const (
expectedf = "From the language %s translated output: %s"
enUS = "hello, iris"
elGR = "γεια, iris"
zhCN = "您好iris"
)
var (
tests = map[string]string{
"en-US": fmt.Sprintf(expectedf, "en-US", "hello, iris"),
"el-GR": fmt.Sprintf(expectedf, "el-GR", "γεια, iris"),
"zh-CN": fmt.Sprintf(expectedf, "zh-CN", "您好iris"),
"en-US": fmt.Sprintf(expectedf, "en-US", enUS),
"el-GR": fmt.Sprintf(expectedf, "el-GR", elGR),
"zh-CN": fmt.Sprintf(expectedf, "zh-CN", zhCN),
}
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) {
Body().Equal(elgrMulti)
e.GET("/en/multi").Expect().Status(httptest.StatusOK).
Body().Equal(enusMulti)
e.GET("/el-GRtemplates").Expect().Status(httptest.StatusNotFound)
e.GET("/el-templates").Expect().Status(httptest.StatusNotFound)
e.GET("/el/templates").Expect().Status(httptest.StatusOK).Body().Contains(elGR).Contains(zhCN)
}