Documentation
¶
Index ¶
- Constants
- func Middleware() gin.HandlerFunc
- func New(config Config) error
- func T(c *gin.Context, key string, args ...interface{}) string
- func TDate(c *gin.Context, t time.Time) string
- func TPlural(c *gin.Context, count int, key string, args ...interface{}) string
- type Config
- type LanguageBundle
- type PluralRuleHandler
Constants ¶
View Source
const ( DefaultLanguageCode = "zh-CN" // 默认语言代码 | Default language code ContextKeyLanguage = "i18nBundle" // 上下文存储键名 | Context storage key name MaxCacheEntries = 1000 // 最大缓存条目数 | Maximum cache entries DefaultDateTimeLayout = time.RFC3339 // 默认日期时间格式 | Default datetime format )
默认配置参数
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶ added in v1.8.7
func Middleware() gin.HandlerFunc
Middleware 语言包注入中间件 Language bundle injection middleware
func New ¶ added in v1.3.0
Init 初始化国际化模块 Initialize internationalization module
参数:
config - 配置参数结构体 | Configuration parameters struct
返回:
error - 初始化过程中遇到的错误 | Error during initialization
Types ¶
type Config ¶ added in v1.8.7
type Config struct { DefaultLang string `comment:"默认语言代码(如'en')| Default language code"` FallbackLang string `comment:"备用回退语言代码 | Fallback language code"` TranslationsDir string `comment:"翻译文件目录路径 | Translation files directory path"` SupportedLangs []string `comment:"支持的语言列表 | Supported languages list"` CacheEnabled bool `comment:"是否启用翻译缓存 | Enable translation cache"` MaxCacheSize int `comment:"缓存最大容量 | Maximum cache size"` CustomPluralRule PluralRuleHandler `comment:"自定义复数规则处理器 | Custom plural rule handler"` DateTimeLayouts map[string]string `comment:"各语言日期时间格式 | Per-language datetime formats"` }
Config 国际化配置结构 Internationalization configuration structure
type LanguageBundle ¶ added in v1.8.7
type LanguageBundle struct {
// contains filtered or unexported fields
}
LanguageBundle 语言包数据结构 Language bundle data structure
Click to show internal directories.
Click to hide internal directories.