mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
This commit is contained in:
@@ -406,7 +406,7 @@ func (i *I18n) GetMessage(ctx *context.Context, format string, args ...interface
|
||||
}
|
||||
|
||||
// Wrapper returns a new router wrapper.
|
||||
// The result function can be passed on `Application.WrapRouter`.
|
||||
// The result function can be passed on `Application.WrapRouter/AddRouterWrapper`.
|
||||
// It compares the path prefix for translated language and
|
||||
// local redirects the requested path with the selected (from the path) language to the router.
|
||||
//
|
||||
@@ -417,7 +417,10 @@ func (i *I18n) Wrapper() router.WrapperFunc {
|
||||
}
|
||||
return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
found := false
|
||||
path := r.URL.Path[1:]
|
||||
path := r.URL.Path
|
||||
if len(path) > 0 && path[0] == '/' {
|
||||
path = path[1:]
|
||||
}
|
||||
|
||||
if idx := strings.IndexByte(path, '/'); idx > 0 {
|
||||
path = path[:idx]
|
||||
@@ -451,7 +454,6 @@ func (i *I18n) Wrapper() router.WrapperFunc {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
next(w, r)
|
||||
|
||||
@@ -172,6 +172,21 @@ func (l MemoryLocalizer) GetLocale(index int) context.Locale {
|
||||
// panic(fmt.Sprintf("locale of index [%d] not found", index))
|
||||
// }
|
||||
// return loc
|
||||
/* Note(@kataras): the following is allowed as a language index can be higher
|
||||
than the length of the locale files.
|
||||
if index >= len(l) || index < 0 {
|
||||
// 1. language exists in the caller but was not found in files.
|
||||
// 2. language exists in both files and caller but the actual
|
||||
// languages are two, while the registered are 4 (when missing files),
|
||||
// that happens when Strict option is false.
|
||||
// force to the default language but what is the default language if the language index is greater than this length?
|
||||
// That's why it's allowed.
|
||||
index = 0
|
||||
}*/
|
||||
|
||||
if index < 0 {
|
||||
index = 0
|
||||
}
|
||||
|
||||
return l[index]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user