Update to 6.1.2

This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-01-13 05:57:46 +02:00
parent c73c2a00c3
commit f380d710cc
5 changed files with 83 additions and 6 deletions

View File

@ -1,4 +1,4 @@
- Version : **6.1.1**
- Version : **6.1.2**
- Operating System:

View File

@ -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`.

View File

@ -18,7 +18,7 @@
<br/>
<a href="https://github.com/kataras/iris/blob/master/HISTORY.md"><img src="https://img.shields.io/badge/%20version%20-%206.1.1%20-blue.svg?style=flat-square" alt="CHANGELOG/HISTORY"></a>
<a href="https://github.com/kataras/iris/blob/master/HISTORY.md"><img src="https://img.shields.io/badge/%20version%20-%206.1.2%20-blue.svg?style=flat-square" alt="CHANGELOG/HISTORY"></a>
<a href="https://github.com/iris-contrib/examples"><img src="https://img.shields.io/badge/%20examples-repository-3362c2.svg?style=flat-square" alt="Examples"></a>
@ -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)**

View File

@ -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

View File

@ -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 = ` _____ _
|_ _| (_)