# README
localeutil

提供了一些常用的本地化相关功能,依赖于 https://pkg.go.dev/golang.org/x/text
- DetectUserLanguage 检测当前用户的本地化信息
- Width 计算字符的宽度
- message 本地化消息
- message/serialize 本地化消息的序列化
- message/extract 本地化消息的提取
安装
go get github.com/issue9/localeutil
版权
# Functions
DefaultWidthOptions 返回默认的配置项的副本
如果要基于默认值作修改,可以采用此方法。.
DetectUserLanguage 检测当前用户的本地化信息
按以下顺序读取本地化信息: - 环境变量 LANGUAGE; - 平台相关,比如 windows 下调用 GetUserDefaultLocaleName 等; - 按顺序读取 LC_ALL、LC_MESSAGES 和 LANG 环境变量;
所有的环境变量遵守 tag.encoding 的格式,比如 zh_CN.UTF-8,其中的 encoding 可以省略。.
DetectUserLanguageTag 检测当前用户的本地化信息
文档说明参考 [DetectUserLanguage].
Error 返回未翻译的错误对象
该对象同时实现了 [Stringer] 接口。 如果 val 中包含 error 对象,可以用 [errors.Is] 进行检测。.
NewPrinter 从 cat 查找最符合 tag 的语言作为打印对象返回.
Phrase 返回一段未翻译的语言片段
key 和 val 参数与 [Printer.Sprintf] 的参数相同。 如果 val 也实现了 [Stringer] 接口,则会先调用 val 的 LocaleString 方法。
如果 val 为空,将返回 StringPhrase(key)。.
Width 采用 [DefaultWidthOptions] 计算字符串的宽度
如果有特殊要求,可以使用 [WidthOptions] 自定义各类字符的宽度。.
# Interfaces
No description provided by the author
# Type aliases
No description provided by the author
No description provided by the author
WidthOptions 用于指定各类字符的宽度
拥有以下几个配置项: - [width.EastAsianFullwidth]: 2 - [width.EastAsianWide]: 2 - [width.EastAsianHalfwidth]: 1 - [width.EastAsianNarrow]: 1 - [width.Neutral]: 1 - [width.EastAsianAmbiguous]: 1
对于 [width.EastAsianAmbiguous] 不同的字体可能有不同的设置。.