diff options
| author | Ho3ein <ho3ein.sanaei@gmail.com> | 2023-05-22 10:56:14 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-22 10:56:14 +0300 |
| commit | 5f489c3d08b36c9569fa67f0c5bf46be8ada7b21 (patch) | |
| tree | 0241a998df1f52f5170aec9bc263414e8a2a3e96 /web/controller/base.go | |
| parent | 3d712890753a4f9981cca95685dec7ad4fff0acf (diff) | |
| parent | f82d0051b2cf827228b5c939d22622bd0d066149 (diff) | |
Merge pull request #491 from hamid-gh98/main
[tgbot] Multi language + More...
Diffstat (limited to 'web/controller/base.go')
| -rw-r--r-- | web/controller/base.go | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/web/controller/base.go b/web/controller/base.go index 98e1831c..674a195d 100644 --- a/web/controller/base.go +++ b/web/controller/base.go @@ -2,6 +2,8 @@ package controller import ( "net/http" + "x-ui/logger" + "x-ui/web/locale" "x-ui/web/session" "github.com/gin-gonic/gin" @@ -13,7 +15,7 @@ type BaseController struct { func (a *BaseController) checkLogin(c *gin.Context) { if !session.IsLogin(c) { if isAjax(c) { - pureJsonMsg(c, false, I18n(c, "pages.login.loginAgain")) + pureJsonMsg(c, false, I18nWeb(c, "pages.login.loginAgain")) } else { c.Redirect(http.StatusTemporaryRedirect, c.GetString("base_path")) } @@ -23,11 +25,13 @@ func (a *BaseController) checkLogin(c *gin.Context) { } } -func I18n(c *gin.Context, name string) string { - anyfunc, _ := c.Get("I18n") - i18n, _ := anyfunc.(func(key string, params ...string) (string, error)) - - message, _ := i18n(name) - - return message +func I18nWeb(c *gin.Context, name string, params ...string) string { + anyfunc, funcExists := c.Get("I18n") + if !funcExists { + logger.Warning("I18n function not exists in gin context!") + return "" + } + i18nFunc, _ := anyfunc.(func(i18nType locale.I18nType, key string, keyParams ...string) string) + msg := i18nFunc(locale.Web, name, params...) + return msg } |
