配置管理与国际化 (i18n)
配置管理与国际化 (i18n)
1. 配置文件管理
应用配置文件建议存放在应用根目录的 conf/config.yaml 中:
app:
name: "demo-app"
version: "1.0.0"
env: "production"
log:
level: "info"
output: "stdout"
features:
enable_terminal: true
max_concurrency: 5Go 端通过 gopkg.in/yaml.v3 读取并解析为强类型 Struct。
2. 国际化多语言支持
在极目桌面中,微应用需要适配不同的语言环境。
package i18n
import "embed"
//go:embed locales/*.json
var localeFS embed.FS
type I18n struct {
lang string
}
func (i *I18n) T(key string) string {
// 根据当前 locale 返回翻译文本
return translate(i.lang, key)
}