mirror of
https://github.com/kataras/iris.git
synced 2025-03-14 08:16:28 +01:00
Update to 6.1.2
This commit is contained in:
parent
c73c2a00c3
commit
f380d710cc
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
|
@ -1,4 +1,4 @@
|
||||||
- Version : **6.1.1**
|
- Version : **6.1.2**
|
||||||
|
|
||||||
- Operating System:
|
- Operating System:
|
||||||
|
|
||||||
|
|
58
HISTORY.md
58
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`.
|
**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
|
## 6.1.0 -> 6.1.1
|
||||||
|
|
||||||
- **NEW FEATURE**: `Offline routes`.
|
- **NEW FEATURE**: `Offline routes`.
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<br/>
|
<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>
|
<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
|
Versioning
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Current: **v6.1.1**
|
Current: **v6.1.2**
|
||||||
|
|
||||||
Older: **[v5/fasthttp](https://github.com/kataras/iris/tree/5.0.0)**
|
Older: **[v5/fasthttp](https://github.com/kataras/iris/tree/5.0.0)**
|
||||||
|
|
||||||
|
|
23
context.go
23
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
|
// GetFmt returns a value which has this format: func(format string, args ...interface{}) string
|
||||||
// if doesn't exists returns nil
|
// if doesn't exists returns a function which returns an empty string.
|
||||||
func (ctx *Context) GetFmt(key string) func(format string, args ...interface{}) 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 {
|
if v, ok := ctx.Get(key).(func(format string, args ...interface{}) string); ok {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
return func(format string, args ...interface{}) string { return "" }
|
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
|
// GetString same as Get but returns the value as string
|
||||||
|
|
2
iris.go
2
iris.go
|
@ -81,7 +81,7 @@ const (
|
||||||
// IsLongTermSupport flag is true when the below version number is a long-term-support version
|
// IsLongTermSupport flag is true when the below version number is a long-term-support version
|
||||||
IsLongTermSupport = false
|
IsLongTermSupport = false
|
||||||
// Version is the current version number of the Iris web framework
|
// Version is the current version number of the Iris web framework
|
||||||
Version = "6.1.1"
|
Version = "6.1.2"
|
||||||
|
|
||||||
banner = ` _____ _
|
banner = ` _____ _
|
||||||
|_ _| (_)
|
|_ _| (_)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user