langx

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package langx 是内置界面文本的 i18n 层:enum 语言 + 进程级目录 + 用户 覆盖。默认英文(xyz 的规范默认);中文随库携带。选择顺序(根派发器负责 落地):--xyz.lang flag > Config.Lang > LANG/LC_ALL 环境检测 > 英文。

T(key) 返回该语言下的文本;Tf(key, params...) 用 {0}、{1}… 占位符做 参数代入(自研最小格式化器,零第三方依赖)。覆盖表(代码侧配置)优先于 内置译文;未命中任何语言的键回退到键名本身(绝不 panic)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Set

func Set(l Language, override map[string]string)

Set 设置进程级语言与可选覆盖表(override 键覆盖内置译文;可为 nil)。 根派发器在解析完配置后调用;嵌入场景可自行调用。

func T

func T(key string) string

T 返回当前语言下 key 的文本:覆盖 > 内置 > 键名回退。

func Tf

func Tf(key string, params ...string) string

Tf 是带参数的 T:模板中的 {0}、{1}… 依次被 params 替换。

Types

type Language

type Language int

Language 是受支持的语言。零值 En(规范默认)。

const (
	En Language = iota
	ZhCn
)

func Detect

func Detect() Language

Detect 按 LANG/LC_ALL 环境做语言检测:zh 前缀 → 中文,其余(C/POSIX/ 缺失)→ 英文。

func Lang

func Lang() Language

Lang 返回当前语言(零配置下为 En)。

func Parse

func Parse(s string) (Language, bool)

Parse 把 --xyz.lang 的取值映射成语言;未知值返回 false(注册期报错)。

func (Language) String

func (l Language) String() string

String 返回 --xyz.lang 的取值形态。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL