1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-27 23:07:03 +00:00

i18n: respect fallback language when Strict is false and no DefaultMessageFunc was provided

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-30 10:36:25 +03:00
parent 5b983800ec
commit 5017e3c986
4 changed files with 43 additions and 66 deletions

View File

@@ -163,20 +163,6 @@ func (loc *Locale) Language() string {
// GetMessage should return translated text based on the given "key".
func (loc *Locale) GetMessage(key string, args ...interface{}) string {
return loc.getMessage(loc.ID, key, args...)
}
// 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.
func (loc *Locale) GetMessageContext(ctx *context.Context, key string, args ...interface{}) string {
langInput := ctx.Values().GetString(ctx.Application().ConfigurationReadOnly().GetLanguageInputContextKey())
return loc.getMessage(langInput, key, args...)
}
func (loc *Locale) getMessage(langInput, key string, args ...interface{}) string {
if msg, ok := loc.Messages[key]; ok {
result, err := msg.Render(args...)
if err != nil {
@@ -186,10 +172,5 @@ func (loc *Locale) getMessage(langInput, key string, args ...interface{}) string
return result
}
if fn := loc.Options.DefaultMessageFunc; fn != nil {
// let langInput to be empty if that's the case.
return fn(langInput, loc.ID, key, args...)
}
return ""
}