Trans template in FuncMap

This commit is contained in:
Alex Lushpai 2022-02-17 10:38:12 +03:00 committed by GitHub
commit bcef82e969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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",