mirror of
https://github.com/retailcrm/mg-transport-core.git
synced 2024-11-21 20:56:04 +03:00
Trans template in FuncMap
This commit is contained in:
commit
bcef82e969
@ -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)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user