i18n

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCurrentLanguage added in v0.0.33

func GetCurrentLanguage() string

func GetEnableLanguage added in v0.0.38

func GetEnableLanguage() string

func LT added in v0.0.33

func LT(locale, content string) string

func LTf added in v0.0.33

func LTf(locale, format string, values ...interface{}) string

func LocaleLoadHook

func LocaleLoadHook(db *gorm.DB)

2. get locale fields

func LocaleUpdateHook

func LocaleUpdateHook(db *gorm.DB)

1. store locale fields

func SetCurrentLanguage added in v0.0.45

func SetCurrentLanguage(locale string)

func Start

func Start()

func T added in v0.0.33

func T(content string) string

func Tf added in v0.0.33

func Tf(format string, values ...interface{}) string

Types

type I18nEnabled added in v0.0.28

type I18nEnabled struct {
	LocaleFields []*LocaleFieldValue `gorm:"-" json:"-"`
}

type I18nFactory

type I18nFactory struct {
	Translator Translator `inject:"translator"`
}

type I18nPropertiesEnabled added in v0.0.46

type I18nPropertiesEnabled interface {
	I18nProperties() string
}

type LocaleFieldValue

type LocaleFieldValue struct {
	EntityName string `gorm:"column:entity_name;primaryKey" json:"entityName"`
	EntityId   string `gorm:"column:entity_id;primaryKey" json:"entityId"`
	Name       string `gorm:"column:name;primaryKey" json:"name"`
	Locale     string `gorm:"column:locale;default:en;primaryKey" json:"locale"`
	Value      string `gorm:"column:value" json:"value"`
}

type Manager added in v0.0.33

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

Manager for i18n contents, it is concurrent safe, supporting hot reload.

func New added in v0.0.33

func New(options ...Options) *Manager

New creates and returns a new i18n manager. The optional parameter `option` specifies the custom options for i18n manager. It uses a default one if it's not passed.

func (*Manager) GetContent added in v0.0.33

func (m *Manager) GetContent(key string) interface{}

GetContent retrieves and returns the configured content for given key and specified language. It returns an empty string if not found.

func (*Manager) LT added in v0.0.33

func (m *Manager) LT(locale, content string) string

T is alias of Translate for convenience.

func (*Manager) LTf added in v0.0.33

func (m *Manager) LTf(locale, format string, values ...interface{}) string

Tf is alias of TranslateFormat for convenience.

func (*Manager) LocaleTranslate added in v0.0.33

func (m *Manager) LocaleTranslate(lang, content string) string

func (*Manager) LocaleTranslateFormat added in v0.0.33

func (m *Manager) LocaleTranslateFormat(locale, format string, values ...interface{}) string

TranslateFormat translates, formats and returns the `format` with configured language and given `values`.

func (*Manager) SetDelimiters added in v0.0.33

func (m *Manager) SetDelimiters(left, right string)

SetDelimiters sets the delimiters for translator.

func (*Manager) SetLanguage added in v0.0.33

func (m *Manager) SetLanguage(language string)

SetLanguage sets the language for translator.

func (*Manager) SetPath added in v0.0.33

func (m *Manager) SetPath(path string) error

SetPath sets the directory path storing i18n files.

func (*Manager) T added in v0.0.33

func (m *Manager) T(content string) string

T is alias of Translate for convenience.

func (*Manager) Translate added in v0.0.33

func (m *Manager) Translate(content string) string

Translate translates `content` with configured language.

func (*Manager) TranslateFormat added in v0.0.33

func (m *Manager) TranslateFormat(format string, values ...interface{}) string

TranslateFormat translates, formats and returns the `format` with configured language and given `values`.

type Options added in v0.0.33

type Options struct {
	Path       string   // I18n files storage path.
	Language   string   // Default local language.
	Delimiters []string // Delimiters for variable parsing.
}

Options is used for i18n object configuration.

type Translator

type Translator interface {
	StoreTranslations(translations []*LocaleFieldValue)
	LoadTranslations(locale, entityName string, entityId ...string) map[string][]*LocaleFieldValue
}

Jump to

Keyboard shortcuts

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