mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Fix router error message's i18n
This commit is contained in:
14
conf/conf.go
14
conf/conf.go
@ -105,6 +105,20 @@ func GetConfigDataSourceName() string {
|
||||
return dataSourceName
|
||||
}
|
||||
|
||||
func GetLanguage(language string) string {
|
||||
if language == "" {
|
||||
return "en"
|
||||
}
|
||||
|
||||
language = language[0:2]
|
||||
|
||||
if strings.Contains(GetConfigString("languages"), language) {
|
||||
return language
|
||||
} else {
|
||||
return "en"
|
||||
}
|
||||
}
|
||||
|
||||
func IsDemoMode() bool {
|
||||
return strings.ToLower(GetConfigString("isDemoMode")) == "true"
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ package controllers
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/casdoor/casdoor/conf"
|
||||
"github.com/casdoor/casdoor/i18n"
|
||||
@ -56,11 +55,8 @@ func (c *ApiController) T(error string) string {
|
||||
|
||||
// GetAcceptLanguage ...
|
||||
func (c *ApiController) GetAcceptLanguage() string {
|
||||
lang := c.Ctx.Request.Header.Get("Accept-Language")
|
||||
if lang == "" || !strings.Contains(conf.GetConfigString("languages"), lang[0:2]) {
|
||||
lang = "en"
|
||||
}
|
||||
return lang[0:2]
|
||||
language := c.Ctx.Request.Header.Get("Accept-Language")
|
||||
return conf.GetLanguage(language)
|
||||
}
|
||||
|
||||
// SetTokenErrorHttpStatus ...
|
||||
|
@ -19,6 +19,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/beego/beego/context"
|
||||
"github.com/casdoor/casdoor/conf"
|
||||
"github.com/casdoor/casdoor/i18n"
|
||||
"github.com/casdoor/casdoor/object"
|
||||
"github.com/casdoor/casdoor/util"
|
||||
)
|
||||
@ -46,8 +48,17 @@ func responseError(ctx *context.Context, error string, data ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
func getAcceptLanguage(ctx *context.Context) string {
|
||||
language := ctx.Request.Header.Get("Accept-Language")
|
||||
return conf.GetLanguage(language)
|
||||
}
|
||||
|
||||
func T(ctx *context.Context, error string) string {
|
||||
return i18n.Translate(getAcceptLanguage(ctx), error)
|
||||
}
|
||||
|
||||
func denyRequest(ctx *context.Context) {
|
||||
responseError(ctx, "Unauthorized operation")
|
||||
responseError(ctx, T(ctx, "auth:Unauthorized operation"))
|
||||
}
|
||||
|
||||
func getUsernameByClientIdSecret(ctx *context.Context) string {
|
||||
|
@ -31,7 +31,7 @@ const demoModeCallback = (res) => {
|
||||
okText: i18next.t("user:OK"),
|
||||
cancelText: i18next.t("general:Cancel"),
|
||||
onOk() {
|
||||
Setting.openLink(`https://demo.casdoor.com${location.path}${location.search}?username=built-in/admin&password=123`);
|
||||
Setting.openLink(`https://demo.casdoor.com${location.pathname}${location.search}?username=built-in/admin&password=123`);
|
||||
},
|
||||
onCancel() {},
|
||||
});
|
||||
|
Reference in New Issue
Block a user