fix: 多语言翻译值转化key进行查询
This commit is contained in:
@@ -3,6 +3,7 @@ package i18n
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
systemService "be.ems/src/modules/system/service"
|
systemService "be.ems/src/modules/system/service"
|
||||||
)
|
)
|
||||||
@@ -70,6 +71,26 @@ func UpdateKeyValue(language, key, value string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TFindKeyPrefix 翻译值查找键 值前缀匹配
|
||||||
|
func TFindKeyPrefix(language, keyPrefix, value string) string {
|
||||||
|
key := value
|
||||||
|
if value == "" {
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
arr, ok := localeMap[language]
|
||||||
|
if !ok || len(arr) == 0 {
|
||||||
|
arr = LoadLocaleData(language)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range arr {
|
||||||
|
if strings.HasPrefix(v.Key, keyPrefix) && strings.HasPrefix(v.Value, value) {
|
||||||
|
key = v.Key
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return key
|
||||||
|
}
|
||||||
|
|
||||||
// TKey 翻译键
|
// TKey 翻译键
|
||||||
func TKey(language, key string) string {
|
func TKey(language, key string) string {
|
||||||
value := key
|
value := key
|
||||||
|
|||||||
@@ -38,12 +38,17 @@ type SysDictDataController struct {
|
|||||||
//
|
//
|
||||||
// GET /list
|
// GET /list
|
||||||
func (s *SysDictDataController) List(c *gin.Context) {
|
func (s *SysDictDataController) List(c *gin.Context) {
|
||||||
querys := ctx.QueryMap(c)
|
|
||||||
data := s.sysDictDataService.SelectDictDataPage(querys)
|
|
||||||
|
|
||||||
rows := data["rows"].([]model.SysDictData)
|
|
||||||
// 闭包函数处理多语言
|
|
||||||
language := ctx.AcceptLanguage(c)
|
language := ctx.AcceptLanguage(c)
|
||||||
|
querys := ctx.QueryMap(c)
|
||||||
|
// 多语言值转key查询
|
||||||
|
if v, ok := querys["dictLabel"]; ok && v != "" {
|
||||||
|
querys["dictLabel"] = i18n.TFindKeyPrefix(language, "dictData", v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
data := s.sysDictDataService.SelectDictDataPage(querys)
|
||||||
|
rows := data["rows"].([]model.SysDictData)
|
||||||
|
|
||||||
|
// 闭包函数处理多语言
|
||||||
converI18n := func(language string, arr *[]model.SysDictData) {
|
converI18n := func(language string, arr *[]model.SysDictData) {
|
||||||
for i := range *arr {
|
for i := range *arr {
|
||||||
if strings.Contains((*arr)[i].DictType, "i18n") {
|
if strings.Contains((*arr)[i].DictType, "i18n") {
|
||||||
|
|||||||
@@ -36,12 +36,17 @@ type SysDictTypeController struct {
|
|||||||
//
|
//
|
||||||
// GET /list
|
// GET /list
|
||||||
func (s *SysDictTypeController) List(c *gin.Context) {
|
func (s *SysDictTypeController) List(c *gin.Context) {
|
||||||
querys := ctx.QueryMap(c)
|
|
||||||
data := s.sysDictTypeService.SelectDictTypePage(querys)
|
|
||||||
|
|
||||||
rows := data["rows"].([]model.SysDictType)
|
|
||||||
// 闭包函数处理多语言
|
|
||||||
language := ctx.AcceptLanguage(c)
|
language := ctx.AcceptLanguage(c)
|
||||||
|
querys := ctx.QueryMap(c)
|
||||||
|
// 多语言值转key查询
|
||||||
|
if v, ok := querys["dictName"]; ok && v != "" {
|
||||||
|
querys["dictName"] = i18n.TFindKeyPrefix(language, "dictType", v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
data := s.sysDictTypeService.SelectDictTypePage(querys)
|
||||||
|
rows := data["rows"].([]model.SysDictType)
|
||||||
|
|
||||||
|
// 闭包函数处理多语言
|
||||||
converI18n := func(language string, arr *[]model.SysDictType) {
|
converI18n := func(language string, arr *[]model.SysDictType) {
|
||||||
for i := range *arr {
|
for i := range *arr {
|
||||||
(*arr)[i].DictName = i18n.TKey(language, (*arr)[i].DictName)
|
(*arr)[i].DictName = i18n.TKey(language, (*arr)[i].DictName)
|
||||||
|
|||||||
@@ -35,12 +35,17 @@ type SysLogOperateController struct {
|
|||||||
//
|
//
|
||||||
// GET /list
|
// GET /list
|
||||||
func (s *SysLogOperateController) List(c *gin.Context) {
|
func (s *SysLogOperateController) List(c *gin.Context) {
|
||||||
querys := ctx.QueryMap(c)
|
|
||||||
data := s.SysLogOperateService.SelectSysLogOperatePage(querys)
|
|
||||||
|
|
||||||
rows := data["rows"].([]model.SysLogOperate)
|
|
||||||
// 闭包函数处理多语言
|
|
||||||
language := ctx.AcceptLanguage(c)
|
language := ctx.AcceptLanguage(c)
|
||||||
|
querys := ctx.QueryMap(c)
|
||||||
|
// 多语言值转key查询
|
||||||
|
if v, ok := querys["title"]; ok && v != "" {
|
||||||
|
querys["title"] = i18n.TFindKeyPrefix(language, "log.operate.title", v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
|
data := s.SysLogOperateService.SelectSysLogOperatePage(querys)
|
||||||
|
rows := data["rows"].([]model.SysLogOperate)
|
||||||
|
|
||||||
|
// 闭包函数处理多语言
|
||||||
converI18n := func(language string, arr *[]model.SysLogOperate) {
|
converI18n := func(language string, arr *[]model.SysLogOperate) {
|
||||||
for i := range *arr {
|
for i := range *arr {
|
||||||
(*arr)[i].Title = i18n.TKey(language, (*arr)[i].Title)
|
(*arr)[i].Title = i18n.TKey(language, (*arr)[i].Title)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (r *SysDictDataImpl) SelectDictDataPage(query map[string]any) map[string]an
|
|||||||
}
|
}
|
||||||
if v, ok := query["dictLabel"]; ok && v != "" {
|
if v, ok := query["dictLabel"]; ok && v != "" {
|
||||||
conditions = append(conditions, "dict_label like concat(?, '%')")
|
conditions = append(conditions, "dict_label like concat(?, '%')")
|
||||||
params = append(params, v)
|
params = append(params, strings.TrimSpace(v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := query["status"]; ok && v != "" {
|
if v, ok := query["status"]; ok && v != "" {
|
||||||
conditions = append(conditions, "status = ?")
|
conditions = append(conditions, "status = ?")
|
||||||
|
|||||||
@@ -62,11 +62,11 @@ func (r *SysDictTypeImpl) SelectDictTypePage(query map[string]any) map[string]an
|
|||||||
var params []any
|
var params []any
|
||||||
if v, ok := query["dictName"]; ok && v != "" {
|
if v, ok := query["dictName"]; ok && v != "" {
|
||||||
conditions = append(conditions, "dict_name like concat(?, '%')")
|
conditions = append(conditions, "dict_name like concat(?, '%')")
|
||||||
params = append(params, v)
|
params = append(params, strings.TrimSpace(v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := query["dictType"]; ok && v != "" {
|
if v, ok := query["dictType"]; ok && v != "" {
|
||||||
conditions = append(conditions, "dict_type like concat(?, '%')")
|
conditions = append(conditions, "dict_type like concat(?, '%')")
|
||||||
params = append(params, v)
|
params = append(params, strings.TrimSpace(v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := query["status"]; ok && v != "" {
|
if v, ok := query["status"]; ok && v != "" {
|
||||||
conditions = append(conditions, "status = ?")
|
conditions = append(conditions, "status = ?")
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func (r *SysLogOperateImpl) SelectSysLogOperatePage(query map[string]any) map[st
|
|||||||
var params []any
|
var params []any
|
||||||
if v, ok := query["title"]; ok && v != "" {
|
if v, ok := query["title"]; ok && v != "" {
|
||||||
conditions = append(conditions, "title like concat(?, '%')")
|
conditions = append(conditions, "title like concat(?, '%')")
|
||||||
params = append(params, v)
|
params = append(params, strings.TrimSpace(v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := query["businessType"]; ok && v != "" {
|
if v, ok := query["businessType"]; ok && v != "" {
|
||||||
conditions = append(conditions, "business_type = ?")
|
conditions = append(conditions, "business_type = ?")
|
||||||
@@ -77,7 +77,7 @@ func (r *SysLogOperateImpl) SelectSysLogOperatePage(query map[string]any) map[st
|
|||||||
}
|
}
|
||||||
if v, ok := query["operName"]; ok && v != "" {
|
if v, ok := query["operName"]; ok && v != "" {
|
||||||
conditions = append(conditions, "oper_name like concat(?, '%')")
|
conditions = append(conditions, "oper_name like concat(?, '%')")
|
||||||
params = append(params, v)
|
params = append(params, strings.TrimSpace(v.(string)))
|
||||||
}
|
}
|
||||||
if v, ok := query["status"]; ok && v != "" {
|
if v, ok := query["status"]; ok && v != "" {
|
||||||
conditions = append(conditions, "status = ?")
|
conditions = append(conditions, "status = ?")
|
||||||
|
|||||||
Reference in New Issue
Block a user