Help us shape the future of Go! Take the 2026 Go Developer Survey

i18n

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package i18n 提供 vhtml CLI 的国际化管理子命令(scan/add)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetConfig

func GetConfig() *runtimeConfig

GetConfig 从当前配置获取运行时配置

func LoadTranslations

func LoadTranslations(outputPath string) (map[string]map[string]interface{}, error)

LoadTranslations 加载翻译文件

func Register

func Register(parent *flags.Flags, c *Config, ui *string)

Register 把 scan/add 子命令注册到 parent(`vhtml i18n`)下。 ui 为全局 -ui 配置指针:子命令经 flags 继承机制直接复用,无需重复注册。

func SaveTranslations

func SaveTranslations(outputPath string, translations map[string]map[string]interface{}, format FormatConfig, defaultLanguage string) error

SaveTranslations 保存翻译文件

Types

type Config

type Config struct {
	Languages       []string `json:"languages" desc:"支持的语言列表,逗号分隔"`
	DefaultLanguage string   `json:"defaultLanguage" desc:"默认语言,作为翻译的基准语言"`
	Output          string   `json:"output" desc:"输出文件路径,翻译文件的保存位置(默认 {ui}/langs.json)"`
	Include         []string `json:"include" desc:"包含的文件模式,支持 glob 语法"`
	Exclude         []string `json:"exclude" desc:"排除的文件模式,支持 glob 语法"`
	Pattern         string   `json:"pattern" desc:"匹配翻译 key 的正则表达式"`
	Indent          int      `json:"indent" desc:"JSON 缩进空格数"`
	SortKeys        bool     `json:"sortKeys" desc:"是否对 key 进行排序"`
}

Config i18n 配置,对应 vhtml.config.json 的 i18n 段。 字段经 flags.AutoRegister 注册为命令行参数(env 为字段名大写)。 扫描入口不复用独立配置:直接使用全局 -ui(见 Register 注入)。

func DefaultConfig

func DefaultConfig() Config

DefaultConfig 返回内置默认配置。

type FormatConfig

type FormatConfig struct {
	Indent        int
	SortKeys      bool
	TrailingComma bool
}

FormatConfig 格式化配置

type ScanConfig

type ScanConfig struct {
	Include []string
	Exclude []string
	Pattern string
}

ScanConfig 扫描配置

Jump to

Keyboard shortcuts

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