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.
Index ¶
- Variables
- func ParseHeader(al string, n int) []string
- func SetDefault(ins *I18n)
- func T(langCode, key string, args ...interface{}) (t string)
- type Config
- type I18n
- func (a *I18n) Get(langCode string) *i18n.Translator
- func (a *I18n) GetAndCache(langCode string) *i18n.Translator
- func (a *I18n) Monitor() *I18n
- func (a *I18n) Reload(langCode string)
- func (a *I18n) T(langCode, key string, args ...interface{}) (t string)
- func (a *I18n) Translate(langCode, key string, args map[string]string) string
- type Language
- func (a *Language) AcquireTranslator(langCode string) *Translate
- func (a *Language) Config() *Config
- func (a *Language) DetectHeader(r engine.Request) string
- func (a *Language) DetectURI(c echo.Context) string
- func (a *Language) Handler(e echo.RouteRegister, i18nJSVarName string)
- func (a *Language) Init(c *Config)
- func (a *Language) Middleware() echo.MiddlewareFunc
- func (a *Language) ReleaseTranslator(tr *Translate)
- func (a *Language) Set(lang string, on bool, args ...bool) *Language
- func (a *Language) Valid(lang string) bool
- type Translate
- func (t *Translate) E(format string, args ...interface{}) error
- func (t *Translate) Lang() echo.LangCode
- func (t *Translate) LangDefault() string
- func (t *Translate) LangExists(langCode string) bool
- func (t *Translate) LangList() []string
- func (t *Translate) Release()
- func (t *Translate) Reset(language string, langObject *Language) *Translate
- func (t *Translate) SetLang(lang string)
- func (t *Translate) T(format string, args ...interface{}) string
Constants ¶
This section is empty.
Variables ¶
var ( LangVarName = `lang` DefaultLang = `zh-CN` )
Functions ¶
func ParseHeader ¶ added in v1.6.0
func SetDefault ¶ added in v1.14.3
func SetDefault(ins *I18n)
Types ¶
type Config ¶
type Config struct {
Project string
Default string
Fallback string
AllList []string
// key: language, value: map[key]value.
//
// Example:
// {
// "en":{
// "label":"English",
// "flag":"🇺🇸"
// },
// "zh-CN":{
// "label":"简体中文",
// "flag":"🇨🇳"
// },
// }
Extra map[string]param.Store
RulesPath []string
MessagesPath []string
// Reload indicates whether to reload the language file each time it is modified.
Reload bool
// contains filtered or unexported fields
}
func (Config) ExtraBy ¶ added in v1.22.9
ExtraBy returns the extra parameters for the specified language. If no extra parameters exist for the language or Extra is nil, returns an empty Store.
type I18n ¶
type I18n struct {
*i18n.TranslatorFactory
// contains filtered or unexported fields
}
func (*I18n) GetAndCache ¶ added in v1.6.0
func (a *I18n) GetAndCache(langCode string) *i18n.Translator
type Language ¶
type Language struct {
List map[string]bool //语种列表
Index []string //索引
Default string //默认语种
I18n *I18n
// contains filtered or unexported fields
}
func (*Language) AcquireTranslator ¶ added in v1.20.0
func (*Language) DetectHeader ¶ added in v1.1.0
func (*Language) Handler ¶ added in v1.6.0
func (a *Language) Handler(e echo.RouteRegister, i18nJSVarName string)
func (*Language) Middleware ¶
func (a *Language) Middleware() echo.MiddlewareFunc
func (*Language) ReleaseTranslator ¶ added in v1.21.0
type Translate ¶
type Translate struct {
// contains filtered or unexported fields
}
func NewTranslate ¶
NewTranslate creates a new Translate instance and initializes it with the given language and language object. Returns a pointer to the initialized Translate struct.
func (*Translate) E ¶ added in v1.4.3
E returns a new error with the translated message using the given format string and arguments.
func (*Translate) LangDefault ¶ added in v1.18.0
LangDefault default language
func (*Translate) LangExists ¶ added in v1.18.0
LangExists language code exists
func (*Translate) Release ¶ added in v1.19.2
func (t *Translate) Release()
Release releases the Translate instance resources and returns it to the pool if it was created from a pool. It sets both code and lang references to nil and optionally returns the instance to the translatePool.
func (*Translate) Reset ¶ added in v1.6.0
Reset sets the language code and language object for the translator language: the language code to set langObject: the language object containing translations Returns the modified Translate instance for method chaining