Browse Source

add localizer middleware to web.go

Hamidreza Ghavami 1 year ago
parent
commit
4865754b3d
1 changed files with 7 additions and 0 deletions
  1. 7 0
      web/web.go

+ 7 - 0
web/web.go

@@ -207,6 +207,13 @@ func (s *Server) initRouter() (*gin.Engine, error) {
 		return nil, err
 	}
 
+	// Apply locale middleware for i18n
+	webI18nFunc := func(key string, params ...string) string {
+		return locale.I18n(locale.Web, key, params...)
+	}
+	engine.FuncMap["i18n"] = webI18nFunc
+	engine.Use(locale.LocalizerMiddleware())
+
 	// set static files and template
 	if config.IsDebug() {
 		// for development