Vestmore_GO/utils/basic/lang.go
2024-04-15 16:08:17 +08:00

32 lines
661 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package basic
import (
"reflect"
"strings"
)
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 {
return strings.TrimSpace(langField.String())
}
}
// 如果无法获取有效的字符串值则返回zh_cn
return "zh_cn"
}