fix: 解决不一致翻译信息改从kvdb中获取不进行程序缓存
This commit is contained in:
@@ -15,14 +15,6 @@ type localeItem struct {
|
|||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// localeMap 国际化数据组
|
|
||||||
var localeMap = make(map[string][]localeItem)
|
|
||||||
|
|
||||||
// ClearLocaleData 清空国际化数据
|
|
||||||
func ClearLocaleData() {
|
|
||||||
localeMap = make(map[string][]localeItem)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LoadLocaleData 加载国际化数据
|
// LoadLocaleData 加载国际化数据
|
||||||
func LoadLocaleData(language string) []localeItem {
|
func LoadLocaleData(language string) []localeItem {
|
||||||
dictType := fmt.Sprintf("i18n_%s", language)
|
dictType := fmt.Sprintf("i18n_%s", language)
|
||||||
@@ -35,16 +27,12 @@ func LoadLocaleData(language string) []localeItem {
|
|||||||
Code: v.DictCode,
|
Code: v.DictCode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
localeMap[language] = localeData
|
|
||||||
return localeData
|
return localeData
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateKeyValue 更新键对应的值
|
// UpdateKeyValue 更新键对应的值
|
||||||
func UpdateKeyValue(language, key, value string) bool {
|
func UpdateKeyValue(language, key, value string) bool {
|
||||||
arr, ok := localeMap[language]
|
arr := LoadLocaleData(language)
|
||||||
if !ok || len(arr) == 0 {
|
|
||||||
arr = LoadLocaleData(language)
|
|
||||||
}
|
|
||||||
|
|
||||||
code := ""
|
code := ""
|
||||||
if key == "" {
|
if key == "" {
|
||||||
@@ -64,7 +52,6 @@ func UpdateKeyValue(language, key, value string) bool {
|
|||||||
item.DictValue = value
|
item.DictValue = value
|
||||||
row := sysDictDataService.UpdateDictData(item)
|
row := sysDictDataService.UpdateDictData(item)
|
||||||
if row > 0 {
|
if row > 0 {
|
||||||
delete(localeMap, language)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,10 +64,7 @@ func TFindKeyPrefix(language, keyPrefix, value string) string {
|
|||||||
if value == "" {
|
if value == "" {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
arr, ok := localeMap[language]
|
arr := LoadLocaleData(language)
|
||||||
if !ok || len(arr) == 0 {
|
|
||||||
arr = LoadLocaleData(language)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if strings.HasPrefix(v.Key, keyPrefix) && strings.HasPrefix(v.Value, value) {
|
if strings.HasPrefix(v.Key, keyPrefix) && strings.HasPrefix(v.Value, value) {
|
||||||
@@ -97,10 +81,7 @@ func TKey(language, key string) string {
|
|||||||
if key == "" {
|
if key == "" {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
arr, ok := localeMap[language]
|
arr := LoadLocaleData(language)
|
||||||
if !ok || len(arr) == 0 {
|
|
||||||
arr = LoadLocaleData(language)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, v := range arr {
|
for _, v := range arr {
|
||||||
if v.Key == key {
|
if v.Key == key {
|
||||||
|
|||||||
@@ -220,7 +220,6 @@ func (s *SysDictTypeController) Remove(c *gin.Context) {
|
|||||||
// PUT /refreshCache
|
// PUT /refreshCache
|
||||||
func (s *SysDictTypeController) RefreshCache(c *gin.Context) {
|
func (s *SysDictTypeController) RefreshCache(c *gin.Context) {
|
||||||
s.sysDictTypeService.ResetDictCache()
|
s.sysDictTypeService.ResetDictCache()
|
||||||
i18n.ClearLocaleData() // 清空国际化数据
|
|
||||||
c.JSON(200, result.Ok(nil))
|
c.JSON(200, result.Ok(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user