i18n

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(lang string)

Init 初始化 i18n,解析语言偏好并加载翻译文件。 传入空字符串时自动从环境变量检测。

func Lang

func Lang() string

Lang 返回当前生效的语言标签。

func SetLang

func SetLang(lang string)

SetLang 切换语言并重建 localizer(用于 --lang flag 覆盖)。

func SetPendingLang added in v0.4.0

func SetPendingLang(lang string)

SetPendingLang 设置待切换的语言(在 main 中提前调用)。 该函数用于在命令构造前设置语言,解决 --help 时 init() 先于语言设置的问题。

func T

func T(id string) string

T 根据 messageID 返回当前语言的翻译文本。 找不到时 fallback 到 messageID 本身。

func Tf

func Tf(id string, data map[string]any) string

Tf 带模板参数的翻译,data 为 map[string]any。

Types

This section is empty.

Jump to

Keyboard shortcuts

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