l10n

package
v0.0.0-...-932f57c Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

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 DoLocalizeTo(db *gorm.DB, mb *presets.ModelBuilder, lb *Builder, ctx *web.EventContext, mid model.ID, localizeTo []string) (localizedTo []string, err error)

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 IsLocalizableFromContext

func IsLocalizableFromContext(ctx context.Context) (localeCode string, isLocalizable bool)

func LocalePathFromContext

func LocalePathFromContext(m interface{}, ctx context.Context) (localePath string)

func MustGetTranslation

func MustGetTranslation(ctx context.Context, key string) string

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

func New

func New(db *gorm.DB) *Builder

func (*Builder) Activity

func (b *Builder) Activity(v *activity.Builder) (r *Builder)

func (*Builder) ContextValueProvider

func (b *Builder) ContextValueProvider(in context.Context) context.Context

func (*Builder) DefaultLocaleCode

func (b *Builder) DefaultLocaleCode(localeCode string) *Builder

func (*Builder) DisableDeletionForDefaultInternationalizedRecord

func (b *Builder) DisableDeletionForDefaultInternationalizedRecord() bool

func (*Builder) EnsureLocale

func (b *Builder) EnsureLocale(in http.Handler) (out http.Handler)

func (*Builder) GetAllLocalePaths

func (b *Builder) GetAllLocalePaths() (r []string)

func (*Builder) GetAtivity

func (b *Builder) GetAtivity() *activity.Builder

func (*Builder) GetCookieName

func (b *Builder) GetCookieName() string

func (*Builder) GetCorrectLocaleCode

func (b *Builder) GetCorrectLocaleCode(r *http.Request) string

func (*Builder) GetCurrentLocaleCodeFromCookie

func (b *Builder) GetCurrentLocaleCodeFromCookie(r *http.Request) (localeCode string)

func (*Builder) GetDefaultLocale

func (b *Builder) GetDefaultLocale() *LocaleInfo

func (*Builder) GetDefaultLocaleCode

func (b *Builder) GetDefaultLocaleCode() string

func (*Builder) GetLocale

func (b *Builder) GetLocale(localeCode string) *LocaleInfo

func (*Builder) GetLocaleLabel

func (b *Builder) GetLocaleLabel(localeCode string) string

func (*Builder) GetModelLocationsI

func (b *Builder) GetModelLocationsI(m *presets.ModelBuilder, mid model.ID) (records []LocaleInterface, err error)

func (*Builder) GetQueryName

func (b *Builder) GetQueryName() string

func (*Builder) GetSupportLocaleCodes

func (b *Builder) GetSupportLocaleCodes() (r []string)

func (*Builder) GetSupportLocaleCodesFromRequest

func (b *Builder) GetSupportLocaleCodesFromRequest(R *http.Request) []string

func (*Builder) Install

func (b *Builder) Install(pb *presets.Builder) error

func (*Builder) IsTurnedOn

func (b *Builder) IsTurnedOn() bool

func (*Builder) LocaleCodeListDataFilter

func (b *Builder) LocaleCodeListDataFilter(m *presets.ModelBuilder, multiple bool) func(ctx *web.EventContext) *vx.FilterItem

func (*Builder) ModelInstall

func (b *Builder) ModelInstall(pb *presets.Builder, m *presets.ModelBuilder) error

func (*Builder) RegisterLocale

func (b *Builder) RegisterLocale(localeCode, localePath, localeLabel string) (r *LocaleInfo)

func (*Builder) SetDisableDeletionForDefaultInternationalizedRecord

func (b *Builder) SetDisableDeletionForDefaultInternationalizedRecord(disableDeletionForDefaultInternationalizedRecord bool) *Builder

func (*Builder) SupportLocalesFunc

func (b *Builder) SupportLocalesFunc(v func(R *http.Request) []string) (r *Builder)

func (*Builder) SupportedLocales

func (b *Builder) SupportedLocales() Locales

func (*Builder) UnRegisterLocales

func (b *Builder) UnRegisterLocales(localeCode ...string) (r *Builder)

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

func EmbedLocale(v any) *Locale

func (*Locale) EmbedLocale

func (l *Locale) EmbedLocale() *Locale

GetLocale get model's locale

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

func MustGetMessages(ctx context.Context) *Messages

type ModelLocalizeOptions

type ModelLocalizeOptions struct {
	LocalizeCallback func(ctx *web.EventContext, from, to any) (post func() (err error), err error)
}

type PublicLocaleInfo

type PublicLocaleInfo struct {
	Code  string
	Path  string
	Label string
}

type SelectLocale

type SelectLocale struct {
	Label string
	Code  string
}

Jump to

Keyboard shortcuts

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