diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 1db030be..a63ed0e5 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,4 +1,4 @@ -- Version : **6.1.1** +- Version : **6.1.2** - Operating System: diff --git a/HISTORY.md b/HISTORY.md index 90dbef93..55d718f8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,64 @@ **How to upgrade**: remove your `$GOPATH/src/github.com/kataras` folder, open your command-line and execute this command: `go get -u github.com/kataras/iris/iris`. +## 6.1.1 -> 6.1.2 + +Better internalization and localization support, with ability to change the cookie's key and context's keys. + +- Real example: https://github.com/iris-contrib/examples/tree/master/middleware_internationalization_i18n + +**read the comments:** +```go +package main + +import ( + "github.com/iris-contrib/middleware/i18n" + "github.com/kataras/iris" +) + +func main() { + + iris.Use(i18n.New(i18n.Config{ + Default: "en-US", + URLParameter: "lang", + Languages: map[string]string{ + "en-US": "./locales/locale_en-US.ini", + "el-GR": "./locales/locale_el-GR.ini", + "zh-CN": "./locales/locale_zh-CN.ini"}})) + + iris.Get("/", func(ctx *iris.Context) { + + // it tries to find the language by: + // ctx.Get("language") , that should be setted on other middleware before the i18n middleware* + // if that was empty then + // it tries to find from the URLParameter setted on the configuration + // if not found then + // it tries to find the language by the "lang" cookie + // if didn't found then it it set to the Default setted on the configuration + + // hi is the key, 'kataras' is the %s on the .ini file + // the second parameter is optional + + // hi := ctx.Translate("hi", "kataras") + // or: + hi := i18n.Translate(ctx, "hi", "kataras") + + language := ctx.Get(iris.TranslateLanguageContextKey) // language is the language key, example 'en-US' + + // The first succeed language found saved at the cookie with name ("language"), + // you can change that by changing the value of the: iris.TranslateLanguageContextKey + ctx.Writef("From the language %s translated output: %s", language, hi) + }) + + // go to http://localhost:8080/?lang=el-GR + // or http://localhost:8080 + // or http://localhost:8080/?lang=zh-CN + iris.Listen(":8080") + +} + +``` + ## 6.1.0 -> 6.1.1 - **NEW FEATURE**: `Offline routes`. diff --git a/README.md b/README.md index d7e3676c..1c5d7543 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@
-CHANGELOG/HISTORY +CHANGELOG/HISTORY Examples @@ -950,7 +950,7 @@ I recommend testing your API using this new library, [httpexpect](https://github Versioning ------------ -Current: **v6.1.1** +Current: **v6.1.2** Older: **[v5/fasthttp](https://github.com/kataras/iris/tree/5.0.0)** diff --git a/context.go b/context.go index 54903919..cc1c678d 100644 --- a/context.go +++ b/context.go @@ -1007,13 +1007,32 @@ func (ctx *Context) Get(key string) interface{} { } // GetFmt returns a value which has this format: func(format string, args ...interface{}) string -// if doesn't exists returns nil -func (ctx *Context) GetFmt(key string) func(format string, args ...interface{}) string { +// if doesn't exists returns a function which returns an empty string. +// +// "translate" is the key of the i18n middlweare +// for more plaese look: https://github.com/iris-contrib/examples/tree/master/middleware_internationalization_i18n +func (ctx *Context) getFmt(key string) func(format string, args ...interface{}) string { if v, ok := ctx.Get(key).(func(format string, args ...interface{}) string); ok { return v } return func(format string, args ...interface{}) string { return "" } +} +// TranslateLanguageContextKey & TranslateFunctionContextKey are used by i18n handlers/middleware +// currently we have only one: https://github.com/iris-contrib/middleware/tree/master/i18n +// but you can use these keys to override the i18n's cookie name (TranslateLanguageContextKey) +// or to store new translate function by using the ctx.Set(iris.TranslateFunctionContextKey, theTrFunc) +var ( + TranslateLanguageContextKey = "language" + TranslateFunctionContextKey = "translate" +) + +// Translate is the i18n (localization) middleware's function, it just +// calls the ctx.getFmt("translate"). +// "translate" is the key of the i18n middlweare +// for more plaese look: https://github.com/iris-contrib/examples/tree/master/middleware_internationalization_i18n +func (ctx *Context) Translate(format string, args ...interface{}) string { + return ctx.getFmt(TranslateFunctionContextKey)(format, args...) } // GetString same as Get but returns the value as string diff --git a/iris.go b/iris.go index f00bf0fe..ae634e1d 100644 --- a/iris.go +++ b/iris.go @@ -81,7 +81,7 @@ const ( // IsLongTermSupport flag is true when the below version number is a long-term-support version IsLongTermSupport = false // Version is the current version number of the Iris web framework - Version = "6.1.1" + Version = "6.1.2" banner = ` _____ _ |_ _| (_)