i18n

package
Version: v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2016 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LocaleHandler

func LocaleHandler(c *gin.Context)

LocaleHandler handler for detcte locale

func Match

func Match(lng string) language.Tag

Match get language.Tag from string

func Migrate

func Migrate(db *gorm.DB)

Migrate migrate database

Types

type DatabaseProvider

type DatabaseProvider struct {
	Db     *gorm.DB        `inject:""`
	Logger *logging.Logger `inject:""`
}

DatabaseProvider db provider

func (*DatabaseProvider) Del

func (p *DatabaseProvider) Del(lng *language.Tag, code string)

Del del locale

func (*DatabaseProvider) Get

func (p *DatabaseProvider) Get(lng *language.Tag, code string) string

Get get locale

func (*DatabaseProvider) Keys

func (p *DatabaseProvider) Keys(lng *language.Tag) ([]string, error)

Keys list locale keys

func (*DatabaseProvider) Set

func (p *DatabaseProvider) Set(lng *language.Tag, code, message string)

Set set locale

type I18n

type I18n struct {
	Provider Provider `inject:""`
	Locales  map[string]map[string]string
	Logger   *logging.Logger `inject:""`
}

I18n i18n helper

func (*I18n) Exist

func (p *I18n) Exist(lang string) bool

Exist is lang exist?

func (*I18n) Items

func (p *I18n) Items(lng string) map[string]interface{}

Items list all items

func (*I18n) Load

func (p *I18n) Load(dir string) error

Load load locales from filesystem

func (*I18n) T

func (p *I18n) T(lng *language.Tag, code string, args ...interface{}) string

T translate by lang tag

func (*I18n) Ts

func (p *I18n) Ts(lng string, code string, args ...interface{}) string

Ts translate by lang

type Locale

type Locale struct {
	ID        uint   `gorm:"primary_key"`
	Lang      string `gorm:"not null;type:varchar(8);index"`
	Code      string `gorm:"not null;index;type:VARCHAR(255)"`
	Message   string `gorm:"not null;type:varchar(800)"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

Locale locale model

type Provider

type Provider interface {
	Set(lang *language.Tag, code, message string)
	Get(lang *language.Tag, code string) string
	Del(lang *language.Tag, code string)
	Keys(lang *language.Tag) ([]string, error)
}

Provider i18n provider

type RedisProvider

type RedisProvider struct {
	Redis  *redis.Pool     `inject:""`
	Logger *logging.Logger `inject:""`
}

RedisProvider redis provider

func (*RedisProvider) Del

func (p *RedisProvider) Del(lng *language.Tag, code string)

Del locale

func (*RedisProvider) Get

func (p *RedisProvider) Get(lng *language.Tag, code string) string

Get get locale

func (*RedisProvider) Keys

func (p *RedisProvider) Keys(lng *language.Tag) ([]string, error)

Keys list all keys

func (*RedisProvider) Set

func (p *RedisProvider) Set(lng *language.Tag, code, message string)

Set set locale

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL