You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool-biz/core/i18n/option.go

41 lines
1.1 KiB
Go

2 years ago
package i18n
import (
"context"
"github.com/nicksnyder/go-i18n/v2/i18n"
"golang.org/x/text/language"
)
type (
BundleConfig struct {
DefaultLanguage language.Tag // 默认语言
RootPath string // 语言文件根路径
FileLoader Loader // 文件读取器
SortedParameterPrefix string // 自排序参数前缀
TagGetter TagGetter
LocalizeConfigGetter LocalizeConfigGetter
}
// MessageWithParameter 带参消息
MessageWithParameter struct {
MessageID string // 消息ID
Params []any // 自排序参数
ParamsWithName map[string]any // 带名参数
}
// TagGetter 当前language获取器
TagGetter func(context context.Context) string
LocalizeConfigGetter func(config BundleConfig, param any) *i18n.LocalizeConfig
Loader interface {
LoadMessage(path string) ([]byte, error)
}
LoaderFunc func(path string) ([]byte, error)
)
func (f LoaderFunc) LoadMessage(path string) ([]byte, error) {
return f(path)
}