mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 13:35:59 +00:00
implement path prefx for i18n middleware, as requested at: #1369
Former-commit-id: b0d6b6e7f368e710b01faad9b70dfa4cebdd8c4d
This commit is contained in:
@@ -68,9 +68,11 @@ type ConfigurationReadOnly interface {
|
||||
GetPostMaxMemory() int64
|
||||
|
||||
// GetTranslateLanguageContextKey returns the configuration's TranslateFunctionContextKey value,
|
||||
// used for i18n.
|
||||
// used for i18n inside templates.
|
||||
GetTranslateFunctionContextKey() string
|
||||
|
||||
// GetTranslateLangFunctionContextKey returns the configuration's TranslateLangFunctionContextKey value,
|
||||
// used for i18n inside templates.
|
||||
GetTranslateLangFunctionContextKey() string
|
||||
// GetTranslateLanguageContextKey returns the configuration's TranslateLanguageContextKey value,
|
||||
// used for i18n.
|
||||
GetTranslateLanguageContextKey() string
|
||||
|
||||
@@ -294,10 +294,16 @@ type Context interface {
|
||||
Values() *memstore.Store
|
||||
// Translate is the i18n (localization) middleware's function,
|
||||
// it calls the Values().Get(ctx.Application().ConfigurationReadOnly().GetTranslateFunctionContextKey())
|
||||
// to execute the translate function and return the localized text value.
|
||||
// to execute the translate function and returns the current localized text value.
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n
|
||||
Translate(format string, args ...interface{}) string
|
||||
// TranslateLang is the i18n (localization) middleware's function,
|
||||
// it calls the Values().Get(ctx.Application().ConfigurationReadOnly().GetTranslateLangFunctionContextKey())
|
||||
// to execute the translate function and returns the localized text value based on the "lang".
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n
|
||||
TranslateLang(lang, format string, args ...interface{}) string
|
||||
|
||||
// +------------------------------------------------------------+
|
||||
// | Path, Host, Subdomain, IP, Headers etc... |
|
||||
@@ -1499,17 +1505,30 @@ func (ctx *context) Values() *memstore.Store {
|
||||
|
||||
// Translate is the i18n (localization) middleware's function,
|
||||
// it calls the Values().Get(ctx.Application().ConfigurationReadOnly().GetTranslateFunctionContextKey())
|
||||
// to execute the translate function and return the localized text value.
|
||||
// to execute the translate function and return the current localized text value.
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n
|
||||
func (ctx *context) Translate(format string, args ...interface{}) string {
|
||||
if cb, ok := ctx.values.Get(ctx.Application().ConfigurationReadOnly().GetTranslateFunctionContextKey()).(func(format string, args ...interface{}) string); ok {
|
||||
if cb, ok := ctx.values.Get(ctx.Application().ConfigurationReadOnly().GetTranslateFunctionContextKey()).(func(string, ...interface{}) string); ok {
|
||||
return cb(format, args...)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// TranslateLang is the i18n (localization) middleware's function,
|
||||
// it calls the Values().Get(ctx.Application().ConfigurationReadOnly().GetTranslateLangFunctionContextKey())
|
||||
// to execute the translate function and returns the localized text value based on the "lang".
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/miscellaneous/i18n
|
||||
func (ctx *context) TranslateLang(lang, format string, args ...interface{}) string {
|
||||
if cb, ok := ctx.values.Get(ctx.Application().ConfigurationReadOnly().GetTranslateLangFunctionContextKey()).(func(string, string, ...interface{}) string); ok {
|
||||
return cb(lang, format, args...)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// +------------------------------------------------------------+
|
||||
// | Path, Host, Subdomain, IP, Headers etc... |
|
||||
// +------------------------------------------------------------+
|
||||
|
||||
Reference in New Issue
Block a user