language

package
v1.7.15 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2024 License: Apache-2.0 Imports: 13 Imported by: 26

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.

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 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) 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) DetectHeader added in v1.1.0

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

func (*Language) DetectURI

func (a *Language) DetectURI(r engine.Request) 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) Set

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

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, i18nObject *I18n) *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) Reset added in v1.6.0

func (t *Translate) Reset(language string, i18nObject *I18n) *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