mirror of
https://github.com/kataras/iris.git
synced 2026-01-07 03:57:10 +00:00
i18n: respect fallback language when Strict is false and no DefaultMessageFunc was provided
This commit is contained in:
@@ -1254,14 +1254,8 @@ func (ctx *Context) GetLocale() Locale {
|
||||
// See `GetLocale` too.
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/i18n
|
||||
func (ctx *Context) Tr(message string, values ...interface{}) string {
|
||||
if locale := ctx.GetLocale(); locale != nil {
|
||||
return locale.GetMessageContext(ctx, message, values...)
|
||||
}
|
||||
|
||||
// This should never happen as the locale fallbacks to
|
||||
// the default.
|
||||
return message
|
||||
func (ctx *Context) Tr(key string, args ...interface{}) string {
|
||||
return ctx.app.I18nReadOnly().TrContext(ctx, key, args...)
|
||||
}
|
||||
|
||||
// +------------------------------------------------------------+
|
||||
|
||||
@@ -7,7 +7,8 @@ import "golang.org/x/text/language"
|
||||
type I18nReadOnly interface {
|
||||
Tags() []language.Tag
|
||||
GetLocale(ctx *Context) Locale
|
||||
Tr(lang string, format string, args ...interface{}) string
|
||||
Tr(lang string, key string, args ...interface{}) string
|
||||
TrContext(ctx *Context, key string, args ...interface{}) string
|
||||
}
|
||||
|
||||
// Locale is the interface which returns from a `Localizer.GetLocale` method.
|
||||
@@ -25,10 +26,4 @@ type Locale interface {
|
||||
Language() string
|
||||
// GetMessage should return translated text based on the given "key".
|
||||
GetMessage(key string, args ...interface{}) string
|
||||
// GetMessageContext same as GetMessage
|
||||
// but it accepts the Context as its first input.
|
||||
// If DefaultMessageFunc was not nil then this Context
|
||||
// will provide the real language input instead of the locale's which
|
||||
// may be the default language one.
|
||||
GetMessageContext(ctx *Context, key string, args ...interface{}) string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user