language

package
v1.22.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 15 Imported by: 25

Documentation

Overview

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016 Wenhui Shen <www.webx.top>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	LangVarName = `lang`
	DefaultLang = `zh-cn`
)

Functions

func ParseHeader added in v1.6.0

func ParseHeader(al string, n int) []string

func SetDefault added in v1.14.3

func SetDefault(ins *I18n)

func T

func T(langCode, key string, args ...interface{}) (t string)

T 多语言翻译

Types

type Config

type Config struct {
	Project      string
	Default      string
	Fallback     string
	AllList      []string
	RulesPath    []string
	MessagesPath []string
	Reload       bool
	// contains filtered or unexported fields
}

func (*Config) Clone added in v1.21.3

func (c *Config) Clone() Config

func (*Config) FSFunc added in v1.3.0

func (c *Config) FSFunc() func(string) http.FileSystem

func (*Config) SetFSFunc added in v1.3.0

func (c *Config) SetFSFunc(fsFunc func(string) http.FileSystem) *Config

type I18n

type I18n struct {
	*i18n.TranslatorFactory
	// contains filtered or unexported fields
}

func NewI18n

func NewI18n(c *Config) *I18n

func (*I18n) Get

func (a *I18n) Get(langCode string) *i18n.Translator

func (*I18n) GetAndCache added in v1.6.0

func (a *I18n) GetAndCache(langCode string) *i18n.Translator

func (*I18n) Monitor

func (a *I18n) Monitor() *I18n

func (*I18n) Reload

func (a *I18n) Reload(langCode string)

func (*I18n) T

func (a *I18n) T(langCode, key string, args ...interface{}) (t string)

func (*I18n) Translate

func (a *I18n) Translate(langCode, key string, args map[string]string) string

type Language

type Language struct {
	List    map[string]bool //语种列表
	Index   []string        //索引
	Default string          //默认语种
	I18n    *I18n
	// contains filtered or unexported fields
}

func New

func New(c ...*Config) *Language

func (*Language) AcquireTranslator added in v1.20.0

func (a *Language) AcquireTranslator(langCode string) *Translate

func (*Language) Config added in v1.18.1

func (a *Language) Config() *Config

func (*Language) DetectHeader added in v1.1.0

func (a *Language) DetectHeader(r engine.Request) string

func (*Language) DetectURI

func (a *Language) DetectURI(c echo.Context) string

func (*Language) Handler added in v1.6.0

func (a *Language) Handler(e echo.RouteRegister, i18nJSVarName string)

func (*Language) Init

func (a *Language) Init(c *Config)

func (*Language) Middleware

func (a *Language) Middleware() echo.MiddlewareFunc

func (*Language) ReleaseTranslator added in v1.21.0

func (a *Language) ReleaseTranslator(tr *Translate)

func (*Language) Set

func (a *Language) Set(lang string, on bool, args ...bool) *Language

Set 记录语言

  • on: 使用启用此语言
  • args[0]: setDefault 是否设置为默认语言
  • args[1]: normalized 是否已经标准格式化 lang 值

func (*Language) Valid

func (a *Language) Valid(lang string) bool

type Translate

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

func NewTranslate

func NewTranslate(language string, langObject *Language) *Translate

func (*Translate) E added in v1.4.3

func (t *Translate) E(format string, args ...interface{}) error

func (*Translate) Lang

func (t *Translate) Lang() echo.LangCode

func (*Translate) LangDefault added in v1.18.1

func (t *Translate) LangDefault() string

LangDefault default language

func (*Translate) LangExists added in v1.18.1

func (t *Translate) LangExists(langCode string) bool

LangExists language code exists

func (*Translate) LangList added in v1.18.1

func (t *Translate) LangList() []string

LangList language list

func (*Translate) Release added in v1.19.2

func (t *Translate) Release()

func (*Translate) Reset added in v1.6.0

func (t *Translate) Reset(language string, langObject *Language) *Translate

func (*Translate) SetLang

func (t *Translate) SetLang(lang string)

func (*Translate) T

func (t *Translate) T(format string, args ...interface{}) string

Jump to

Keyboard shortcuts

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