1
0

feat: 多语言处理tkey

This commit is contained in:
TsMask
2023-11-21 14:42:37 +08:00
parent f490d9af0f
commit d5d3feb5fc
61 changed files with 1381 additions and 757 deletions

View File

@@ -82,13 +82,13 @@ func UaOsBrowser(c *gin.Context) (string, string) {
userAgent := c.GetHeader("user-agent")
uaInfo := ua.Info(userAgent)
browser := "Unknown Unknown"
browser := "app.common.noUaOsBrowser"
bName, bVersion := uaInfo.Browser()
if bName != "" && bVersion != "" {
browser = bName + " " + bVersion
}
os := "Unknown Unknown"
os := "app.common.noUaOsBrowser"
bos := uaInfo.OS()
if bos != "" {
os = bos
@@ -116,7 +116,8 @@ func LoginUser(c *gin.Context) (vo.LoginUser, error) {
if exists {
return value.(vo.LoginUser), nil
}
return vo.LoginUser{}, fmt.Errorf("invalid login user information")
// 登录用户信息无效
return vo.LoginUser{}, fmt.Errorf("app.common.noLoginUser")
}
// LoginUserToUserID 登录用户信息-用户ID

View File

@@ -294,3 +294,20 @@ func ChunkMergeFile(identifier, originalFileName, subPath string) (string, error
urlPath := filepath.Join(prefix, filePath, fileName)
return filepath.ToSlash(urlPath), nil
}
// ParseUploadFileDir 得到上传资源目录
//
// subPath 子路径,默认 UploadSubPath.DEFAULT
func ParseUploadFileDir(subPath string) string {
_, dir := resourceUpload()
filePath := filepath.Join(subPath, date.ParseDatePath(time.Now()))
return filepath.Join(dir, filePath)
}
// ParseUploadFilePath 本地资源路径
//
// filePath 上传文件路径
func ParseUploadFilePath(filePath string) string {
prefix, dir := resourceUpload()
return strings.Replace(filePath, prefix, dir, 1)
}

View File

@@ -43,7 +43,7 @@ func RegionSearchByIp(ip string) (string, int, int64) {
ip = ClientIP(ip)
if ip == LOCAT_HOST {
// "0|0|0|内网IP|内网IP"
return "0|0|0|Intranet IP|Intranet IP", 0, 0
return "0|0|0|app.common.noIPregion|app.common.noIPregion", 0, 0
}
tStart := time.Now()
region, err := searcher.SearchByStr(ip)
@@ -60,19 +60,19 @@ func RegionSearchByIp(ip string) (string, int, int64) {
func RealAddressByIp(ip string) string {
ip = ClientIP(ip)
if ip == LOCAT_HOST {
return "Intranet IP" // 内网IP
return "app.common.noIPregion" // 内网IP
}
region, err := searcher.SearchByStr(ip)
if err != nil {
logger.Errorf("failed to SearchIP(%s): %s\n", ip, err)
return "unknown" // 未知
return "app.common.unknown" // 未知
}
parts := strings.Split(region, "|")
province := parts[2]
city := parts[3]
if province == "0" && city != "0" {
if city == "内网IP" {
return "Intranet IP" // 内网IP
return "app.common.noIPregion" // 内网IP
}
return city
}