trans template in FuncMap

This commit is contained in:
Tyschitskaya Maria 2022-02-17 09:39:25 +03:00
parent 0126dc9910
commit df2a898092
2 changed files with 17 additions and 1 deletions

View File

@ -137,6 +137,23 @@ func (l *Localizer) LocalizationMiddleware() gin.HandlerFunc {
func (l *Localizer) LocalizationFuncMap() template.FuncMap { func (l *Localizer) LocalizationFuncMap() template.FuncMap {
return template.FuncMap{ return template.FuncMap{
"trans": l.GetLocalizedMessage, "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)
},
} }
} }

View File

@ -73,7 +73,6 @@ func (s *ValidatorSuite) Test_ValidationSuccess() {
"https://raisa.retailcrm.es", "https://raisa.retailcrm.es",
"https://blabla.simla.com", "https://blabla.simla.com",
"https://blabla.simlachat.com", "https://blabla.simlachat.com",
"https://blabla.simlachat.ru",
"https://blabla.ecomlogic.com", "https://blabla.ecomlogic.com",
"https://crm.baucenter.ru", "https://crm.baucenter.ru",
"https://crm.holodilnik.ru", "https://crm.holodilnik.ru",