Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com>2023-05-20 18:19:39 +0300
committerHamidreza Ghavami <70919649+hamid-gh98@users.noreply.github.com>2023-05-20 18:19:39 +0300
commit2bd706aa92c2cbb095ca518cd48a73d4ed5d16cc (patch)
treefd21088d931ea6d24e483043f5f8a2391f3c93a7 /web/controller
parent95e0d9a468dbf569daf65abc01c18f8f0f020dc1 (diff)
update I18n function for controller
Diffstat (limited to 'web/controller')
-rw-r--r--web/controller/base.go20
1 files changed, 12 insertions, 8 deletions
diff --git a/web/controller/base.go b/web/controller/base.go
index 98e1831c..53c80f07 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, WebI18n(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 WebI18n(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
}