l10n

package
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	WrapHandlerKey  = "l10nWrapHandlerKey"
	MenuTopItemFunc = "l10nMenuTopItemFunc"
	SlugLocaleCode  = "locale_code"
)
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 (
	InternationalSvg = `` /* 4392-byte string literal not displayed */

	ChinaSvg = `` /* 1039-byte string literal not displayed */

	JapanSvg = `` /* 473-byte string literal not displayed */

)
View Source
const I18nLocalizeKey i18n.ModuleKey = "I18nLocalizeKey"
View Source
const LocaleCode l10nContextKey = iota

Variables

View Source
var IncorrectLocaleErr = errors.New("incorrect locale")
View Source
var Messages_en_US = &Messages{
	Localize:              "Localize",
	LocalizeFrom:          "From",
	LocalizeTo:            "To",
	SuccessfullyLocalized: "Successfully Localized",
	Location:              "Location",
	Colon:                 ":",
	International:         "International",
	China:                 "China",
	Japan:                 "Japan",
}
View Source
var Messages_ja_JP = &Messages{
	Localize:              "ローカライズ",
	LocalizeFrom:          "から",
	LocalizeTo:            "に",
	SuccessfullyLocalized: "ローカライズに成功しました",
	Location:              "場所",
	Colon:                 ":",
	International:         "国際的",
	China:                 "中国",
	Japan:                 "日本",
}
View Source
var Messages_zh_CN = &Messages{
	Localize:              "本地化",
	LocalizeFrom:          "从",
	LocalizeTo:            "到",
	SuccessfullyLocalized: "本地化成功",
	Location:              "地区",
	Colon:                 ":",
	International:         "全球",
	China:                 "中国",
	Japan:                 "日本",
}

Functions

func IsLocalizable

func IsLocalizable(obj interface{}) (isLocalizable bool)

func IsLocalizableFromContext added in v3.0.1

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

func LocalePathFromContext added in v3.0.1

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

func MustGetTranslation added in v3.0.1

func MustGetTranslation(r *http.Request, 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 added in v3.0.1

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

func (*Builder) ContextValueProvider added in v3.0.1

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

func (*Builder) EnsureLocale

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

func (*Builder) GetAllLocalePaths

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

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) GetLocaleImg added in v3.0.2

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

func (*Builder) GetLocaleLabel

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

func (*Builder) GetLocalePath

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

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 added in v3.0.1

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

func (*Builder) IsTurnedOn

func (b *Builder) IsTurnedOn() bool

func (*Builder) ModelInstall added in v3.0.1

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

func (*Builder) RegisterLocales

func (b *Builder) RegisterLocales(localeCode, localePath, localeLabel, img string) (r *Builder)

func (*Builder) SupportLocalesFunc added in v3.0.1

func (b *Builder) SupportLocalesFunc(v func(R *http.Request) []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 added in v3.0.1

func EmbedLocale(v any) *Locale

func (*Locale) EmbedLocale added in v3.0.1

func (l *Locale) EmbedLocale() *Locale

GetLocale get model's locale

type LocaleInterface added in v3.0.1

type LocaleInterface interface {
	EmbedLocale() *Locale
}

type Messages added in v3.0.1

type Messages struct {
	Localize              string
	LocalizeFrom          string
	LocalizeTo            string
	SuccessfullyLocalized string
	Location              string
	Colon                 string
	International         string
	China                 string
	Japan                 string
}

type SelectLocale added in v3.0.1

type SelectLocale struct {
	// label is a descriptive name used to display the name of a language or region to the user.
	// It is usually a user-friendly string, such as "English", "French", "Chinese", etc. In the user interface,
	// it is used to display selectable localization options.
	Label string

	// code is an identifier that represents a language or locale.
	// It is usually a string that represents a specific language or region code, such as "en" (English), "fr" (French), "zh" (Chinese), etc. In code,
	// it is used to distinguish between different localized versions.
	Code string
}

Jump to

Keyboard shortcuts

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