2024-04-12 09:17:10 +00:00
|
|
|
|
package basic
|
|
|
|
|
|
2024-04-15 08:08:17 +00:00
|
|
|
|
import (
|
|
|
|
|
"reflect"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
2024-04-12 09:17:10 +00:00
|
|
|
|
|
|
|
|
|
func GetLangString(param any) string {
|
|
|
|
|
// 获取参数的反射值
|
|
|
|
|
value := reflect.ValueOf(param)
|
|
|
|
|
|
|
|
|
|
// 如果参数是指针,则获取指针指向的值
|
|
|
|
|
if value.Kind() == reflect.Ptr {
|
|
|
|
|
value = value.Elem()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果参数是结构体
|
|
|
|
|
if value.Kind() == reflect.Struct {
|
|
|
|
|
// 通过字段名获取字段值
|
|
|
|
|
langField := value.FieldByName("Lang")
|
|
|
|
|
|
|
|
|
|
// 如果字段存在并且是字符串类型
|
|
|
|
|
if langField.IsValid() && langField.Kind() == reflect.String {
|
2024-04-15 08:08:17 +00:00
|
|
|
|
return strings.TrimSpace(langField.String())
|
2024-04-12 09:17:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果无法获取有效的字符串值,则返回zh_cn
|
2024-04-15 08:08:17 +00:00
|
|
|
|
|
2024-04-12 09:17:10 +00:00
|
|
|
|
return "zh_cn"
|
|
|
|
|
}
|