fix: 多语言翻译值转化key进行查询

This commit is contained in:
TsMask
2024-03-25 12:01:11 +08:00
parent f22c4b876d
commit decab2d82f
7 changed files with 56 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ package i18n
import (
"fmt"
"regexp"
"strings"
systemService "be.ems/src/modules/system/service"
)
@@ -70,6 +71,26 @@ func UpdateKeyValue(language, key, value string) bool {
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 翻译键
func TKey(language, key string) string {
value := key