From df2a898092bb35eb5ea4e44926714eede7a2eccc Mon Sep 17 00:00:00 2001 From: Tyschitskaya Maria Date: Thu, 17 Feb 2022 09:39:25 +0300 Subject: [PATCH] trans template in FuncMap --- core/localizer.go | 17 +++++++++++++++++ core/validator_test.go | 1 - 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/core/localizer.go b/core/localizer.go index 278c0cc..b00c92c 100644 --- a/core/localizer.go +++ b/core/localizer.go @@ -137,6 +137,23 @@ func (l *Localizer) LocalizationMiddleware() gin.HandlerFunc { func (l *Localizer) LocalizationFuncMap() template.FuncMap { return template.FuncMap{ "trans": l.GetLocalizedMessage, + "transTpl": func(messageID string, parts ...string) string { + if len(parts) == 0 { + return l.GetLocalizedMessage(messageID) + } + + if len(parts)%2 != 0 { + parts = append(parts, "") + } + + partsMap := make(map[string]interface{}, len(parts)/2) + + for i := 0; i < len(parts)-1; i += 2 { + partsMap[parts[i]] = parts[i+1] + } + + return l.GetLocalizedTemplateMessage(messageID, partsMap) + }, } } diff --git a/core/validator_test.go b/core/validator_test.go index 9b8df61..9ec3978 100644 --- a/core/validator_test.go +++ b/core/validator_test.go @@ -73,7 +73,6 @@ func (s *ValidatorSuite) Test_ValidationSuccess() { "https://raisa.retailcrm.es", "https://blabla.simla.com", "https://blabla.simlachat.com", - "https://blabla.simlachat.ru", "https://blabla.ecomlogic.com", "https://crm.baucenter.ru", "https://crm.holodilnik.ru",