Documentation
¶
Overview ¶
Package langx 是内置界面文本的 i18n 层:enum 语言 + 进程级目录 + 用户 覆盖。默认英文(xyz 的规范默认);中文随库携带。选择顺序(根派发器负责 落地):--xyz.lang flag > Config.Lang > LANG/LC_ALL 环境检测 > 英文。
T(key) 返回该语言下的文本;Tf(key, params...) 用 {0}、{1}… 占位符做 参数代入(自研最小格式化器,零第三方依赖)。覆盖表(代码侧配置)优先于 内置译文;未命中任何语言的键回退到键名本身(绝不 panic)。
Index ¶
- func Set(l Language, override map[string]string)
- func T(key string) string
- func Tctx(ctx context.Context, key string) string
- func Tf(key string, params ...string) string
- func Tfctx(ctx context.Context, key string, params ...string) string
- func WithLang(ctx context.Context, l Language) context.Context
- type Language
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Language ¶
type Language int
Language 是受支持的语言。零值 En(规范默认)。
func ParseAcceptLanguage ¶ added in v0.4.4
ParseAcceptLanguage 解析 HTTP Accept-Language 头,返回最匹配的受支持语言 (zh* → ZhCn,en* → En),按 q 值择优(缺省 q=1)。无可解析的受支持标签 时返回 (En, false),调用方据此回退到默认语言。示例:
"zh-CN,zh;q=0.9,en;q=0.8" → (ZhCn, true) "en-US,en;q=0.9" → (En, true) "fr,de;q=0.9" → (En, false) // 无受支持标签