Documentation
¶
Index ¶
- Constants
- Variables
- func DoLocalizeTo(db *gorm.DB, mb *presets.ModelBuilder, lb *Builder, ctx *web.EventContext, ...) (localizedTo []string, err error)
- func GetModelLocations[T LocaleInterface](b *Builder, m *presets.ModelBuilder, obj T) (_ []*T, err error)
- func IsLocalizable(obj interface{}) (isLocalizable bool)
- func IsLocalizableFromContext(ctx context.Context) (localeCode string, isLocalizable bool)
- func LocalePathFromContext(m interface{}, ctx context.Context) (localePath string)
- func ModelWithOptions(mb *presets.ModelBuilder, cfg *ModelLocalizeOptions) *presets.ModelBuilder
- func MustGetTranslation(ctx context.Context, key string) string
- type Builder
- func (b *Builder) Activity(v *activity.Builder) (r *Builder)
- func (b *Builder) ContextValueProvider(in context.Context) context.Context
- func (b *Builder) DefaultLocaleCode(localeCode string) *Builder
- func (b *Builder) DisableDeletionForDefaultInternationalizedRecord() bool
- func (b *Builder) EnsureLocale(in http.Handler) (out http.Handler)
- func (b *Builder) GetAllLocalePaths() (r []string)
- func (b *Builder) GetAtivity() *activity.Builder
- func (b *Builder) GetCookieName() string
- func (b *Builder) GetCorrectLocaleCode(r *http.Request) string
- func (b *Builder) GetCurrentLocaleCodeFromCookie(r *http.Request) (localeCode string)
- func (b *Builder) GetDefaultLocale() *LocaleInfo
- func (b *Builder) GetDefaultLocaleCode() string
- func (b *Builder) GetLocale(localeCode string) *LocaleInfo
- func (b *Builder) GetLocaleLabel(localeCode string) string
- func (b *Builder) GetModelLocationsI(m *presets.ModelBuilder, mid model.ID) (records []LocaleInterface, err error)
- func (b *Builder) GetQueryName() string
- func (b *Builder) GetSupportLocaleCodes() (r []string)
- func (b *Builder) GetSupportLocaleCodesFromRequest(R *http.Request) []string
- func (b *Builder) Install(pb *presets.Builder) error
- func (b *Builder) IsTurnedOn() bool
- func (b *Builder) LocaleCodeListDataFilter(m *presets.ModelBuilder, multiple bool) func(ctx *web.EventContext) *vx.FilterItem
- func (b *Builder) ModelInstall(pb *presets.Builder, m *presets.ModelBuilder) error
- func (b *Builder) RegisterLocale(localeCode, localePath, localeLabel string) (r *LocaleInfo)
- func (b *Builder) SetDisableDeletionForDefaultInternationalizedRecord(disableDeletionForDefaultInternationalizedRecord bool) *Builder
- func (b *Builder) SupportLocalesFunc(v func(R *http.Request) []string) (r *Builder)
- func (b *Builder) SupportedLocales() Locales
- func (b *Builder) UnRegisterLocales(localeCode ...string) (r *Builder)
- type Locale
- type LocaleInfo
- type LocaleInterface
- type Locales
- type Messages
- type ModelLocalizeOptions
- type PublicLocaleInfo
- type SelectLocale
Constants ¶
View Source
const ( LocaleCode l10nContextKey = iota SkipLocaleCode LocalizeOptions )
View Source
const ( WrapHandlerKey = "l10nWrapHandlerKey" MenuTopItemFunc = "l10nMenuTopItemFunc" SlugLocaleCode = "locale_code" BuilderKey = "l10nBuilderKey" )
View Source
const ( Localize = "l10n_LocalizeEvent" DoLocalize = "l10n_DoLocalizeEvent" FromID = "l10n_DoLocalize_FromID" FromVersion = "l10n_DoLocalize_FromVersion" FromLocale = "l10n_DoLocalize_FromLocale" LocalizeFrom = "Localize From" LocalizeTo = "Localize To" )
View Source
const ( FieldLocationLabel = "L10nLocationLabel" FieldLocations = "L10nLocations" )
View Source
const FieldLocalizedEntries = "Localizations"
View Source
const I18nLocalizeKey i18n.ModuleKey = "I18nLocalizeKey"
Variables ¶
View Source
var IncorrectLocaleErr = errors.New("incorrect locale")
View Source
var Messages_en_US = &Messages{
Localize: "Localize",
LocalizeFrom: "From",
LocalizeTo: "To",
CurrentLocalizations: "Current Localizations",
Actions: "Actions",
Localizations: "Localizations",
SuccessfullyLocalized: "Successfully Localized",
Location: "Location",
Colon: ":",
International: "International",
China: "China",
Japan: "Japan",
ErrDeleteInternationalizedRecord: "It is not possible to delete the standard language record when it has is internationalized.",
}
View Source
var Messages_ja_JP = &Messages{ Localize: "ローカライズ", LocalizeFrom: "から", LocalizeTo: "に", CurrentLocalizations: Messages_en_US.CurrentLocalizations, Actions: Messages_en_US.Actions, Localizations: Messages_en_US.Localizations, SuccessfullyLocalized: "ローカライズに成功しました", Location: "場所", Colon: ":", International: "インターナショナル", China: "中国", Japan: "日本", ErrDeleteInternationalizedRecord: Messages_en_US.ErrDeleteInternationalizedRecord, }
View Source
var Messages_zh_CN = &Messages{ Localize: "本地化", LocalizeFrom: "从", LocalizeTo: "到", CurrentLocalizations: Messages_en_US.CurrentLocalizations, Actions: Messages_en_US.Actions, Localizations: Messages_en_US.Localizations, SuccessfullyLocalized: "本地化成功", Location: "地区", Colon: ":", International: "全球", China: "中国", Japan: "日本", ErrDeleteInternationalizedRecord: Messages_en_US.ErrDeleteInternationalizedRecord, }
Functions ¶
func DoLocalizeTo ¶
func GetModelLocations ¶
func GetModelLocations[T LocaleInterface](b *Builder, m *presets.ModelBuilder, obj T) (_ []*T, err error)
func IsLocalizable ¶
func IsLocalizable(obj interface{}) (isLocalizable bool)
func LocalePathFromContext ¶
func ModelWithOptions ¶
func ModelWithOptions(mb *presets.ModelBuilder, cfg *ModelLocalizeOptions) *presets.ModelBuilder
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
func (*Builder) ContextValueProvider ¶
func (*Builder) DefaultLocaleCode ¶
func (*Builder) DisableDeletionForDefaultInternationalizedRecord ¶
func (*Builder) GetAllLocalePaths ¶
func (*Builder) GetAtivity ¶
func (*Builder) GetCookieName ¶
func (*Builder) GetCorrectLocaleCode ¶
func (*Builder) GetCurrentLocaleCodeFromCookie ¶
func (*Builder) GetDefaultLocale ¶
func (b *Builder) GetDefaultLocale() *LocaleInfo
func (*Builder) GetDefaultLocaleCode ¶
func (*Builder) GetLocale ¶
func (b *Builder) GetLocale(localeCode string) *LocaleInfo
func (*Builder) GetLocaleLabel ¶
func (*Builder) GetModelLocationsI ¶
func (b *Builder) GetModelLocationsI(m *presets.ModelBuilder, mid model.ID) (records []LocaleInterface, err error)
func (*Builder) GetQueryName ¶
func (*Builder) GetSupportLocaleCodes ¶
func (*Builder) GetSupportLocaleCodesFromRequest ¶
func (*Builder) IsTurnedOn ¶
func (*Builder) LocaleCodeListDataFilter ¶
func (b *Builder) LocaleCodeListDataFilter(m *presets.ModelBuilder, multiple bool) func(ctx *web.EventContext) *vx.FilterItem
func (*Builder) ModelInstall ¶
func (*Builder) RegisterLocale ¶
func (b *Builder) RegisterLocale(localeCode, localePath, localeLabel string) (r *LocaleInfo)
func (*Builder) SetDisableDeletionForDefaultInternationalizedRecord ¶
func (*Builder) SupportLocalesFunc ¶
func (*Builder) SupportedLocales ¶
func (*Builder) UnRegisterLocales ¶
type Locale ¶
type Locale struct {
LocaleCode string `sql:"size:20" gorm:"primaryKey;default:''"`
}
Locale embed this struct into GROM-backend models to enable localization feature for your model
func EmbedLocale ¶
type LocaleInfo ¶
type LocaleInfo struct { datafield.DataField[*LocaleInfo] // contains filtered or unexported fields }
func (*LocaleInfo) Code ¶
func (l *LocaleInfo) Code() string
func (*LocaleInfo) Export ¶
func (l *LocaleInfo) Export() *PublicLocaleInfo
func (*LocaleInfo) Label ¶
func (l *LocaleInfo) Label() string
func (*LocaleInfo) Path ¶
func (l *LocaleInfo) Path() string
func (*LocaleInfo) String ¶
func (l *LocaleInfo) String() string
type LocaleInterface ¶
type LocaleInterface interface {
EmbedLocale() *Locale
}
type Locales ¶
type Locales []*LocaleInfo
func (Locales) Exported ¶
func (s Locales) Exported() (r []*PublicLocaleInfo)
type Messages ¶
type Messages struct { Localize string LocalizeFrom string LocalizeTo string CurrentLocalizations string Actions string Localizations string SuccessfullyLocalized string Location string Colon string International string China string Japan string ErrDeleteInternationalizedRecord string }
func MustGetMessages ¶
type ModelLocalizeOptions ¶
type ModelLocalizeOptions struct {
LocalizeCallback func(ctx *web.EventContext, from, to any) (post func() (err error), err error)
}
type PublicLocaleInfo ¶
type SelectLocale ¶
Click to show internal directories.
Click to hide internal directories.