mirror of
https://github.com/kataras/iris.git
synced 2026-05-14 01:53:46 +00:00
update dependencies
This commit is contained in:
@@ -366,7 +366,7 @@ func (i *I18n) TryMatchString(s string) (language.Tag, int, bool) {
|
||||
//
|
||||
// It returns an empty string if "lang" not matched, unless DefaultMessageFunc.
|
||||
// It returns the default language's translation if "key" not matched, unless DefaultMessageFunc.
|
||||
func (i *I18n) Tr(lang, key string, args ...interface{}) string {
|
||||
func (i *I18n) Tr(lang, key string, args ...any) string {
|
||||
_, index, ok := i.TryMatchString(lang)
|
||||
if !ok {
|
||||
index = 0
|
||||
@@ -378,13 +378,13 @@ func (i *I18n) Tr(lang, key string, args ...interface{}) string {
|
||||
// TrContext returns the localized text message for this Context.
|
||||
// It returns an empty string if context's locale not matched, unless DefaultMessageFunc.
|
||||
// It returns the default language's translation if "key" not matched, unless DefaultMessageFunc.
|
||||
func (i *I18n) TrContext(ctx *context.Context, key string, args ...interface{}) string {
|
||||
func (i *I18n) TrContext(ctx *context.Context, key string, args ...any) string {
|
||||
loc := ctx.GetLocale()
|
||||
langInput := ctx.Values().GetString(ctx.Application().ConfigurationReadOnly().GetLanguageInputContextKey())
|
||||
return i.getLocaleMessage(loc, langInput, key, args...)
|
||||
}
|
||||
|
||||
func (i *I18n) getLocaleMessage(loc context.Locale, langInput string, key string, args ...interface{}) (msg string) {
|
||||
func (i *I18n) getLocaleMessage(loc context.Locale, langInput string, key string, args ...any) (msg string) {
|
||||
langMatched := ""
|
||||
|
||||
if loc != nil {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package internal
|
||||
|
||||
// Map is just an alias of the map[string]interface{} type.
|
||||
// Map is just an alias of the map[string]any type.
|
||||
// Just like the iris.Map one.
|
||||
type Map = map[string]interface{}
|
||||
type Map = map[string]any
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
//
|
||||
// Note: we don't accept the Context here because Tr method and template func {{ tr }}
|
||||
// have no direct access to it.
|
||||
type MessageFunc func(langInput, langMatched, key string, args ...interface{}) string
|
||||
type MessageFunc func(langInput, langMatched, key string, args ...any) string
|
||||
|
||||
// Catalog holds the locales and the variables message storage.
|
||||
type Catalog struct {
|
||||
|
||||
@@ -160,7 +160,7 @@ func (loc *Locale) Language() string {
|
||||
}
|
||||
|
||||
// GetMessage should return translated text based on the given "key".
|
||||
func (loc *Locale) GetMessage(key string, args ...interface{}) string {
|
||||
func (loc *Locale) GetMessage(key string, args ...any) string {
|
||||
if msg, ok := loc.Messages[key]; ok {
|
||||
result, err := msg.Render(args...)
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// Renderer is responsible to render a translation based
|
||||
// on the given "args".
|
||||
type Renderer interface {
|
||||
Render(args ...interface{}) (string, error)
|
||||
Render(args ...any) (string, error)
|
||||
}
|
||||
|
||||
// Message is the default Renderer for translation messages.
|
||||
@@ -60,7 +60,7 @@ func (m *Message) AddPlural(form PluralForm, r Renderer) {
|
||||
// of the message is the "PluralCount". And for variables the user
|
||||
// should set a message key which looks like: %VAR_NAME%Count, e.g. "DogsCount"
|
||||
// to set plural count for the "Dogs" variable, case-sensitive.
|
||||
func (m *Message) Render(args ...interface{}) (string, error) {
|
||||
func (m *Message) Render(args ...any) (string, error) {
|
||||
if m.Plural {
|
||||
if len(args) > 0 {
|
||||
if pluralCount, ok := findPluralCount(args[0]); ok {
|
||||
|
||||
@@ -42,7 +42,7 @@ func newIndependentPluralRenderer(c *Catalog, loc *Locale, key string, msgs ...c
|
||||
return &independentPluralRenderer{key, printer}, nil
|
||||
}
|
||||
|
||||
func (m *independentPluralRenderer) Render(args ...interface{}) (string, error) {
|
||||
func (m *independentPluralRenderer) Render(args ...any) (string, error) {
|
||||
return m.printer.Sprintf(m.key, args...), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func NewTemplate(c *Catalog, m *Message) (*Template, error) {
|
||||
}
|
||||
|
||||
bufPool := &sync.Pool{
|
||||
New: func() interface{} {
|
||||
New: func() any {
|
||||
return new(bytes.Buffer)
|
||||
},
|
||||
}
|
||||
@@ -86,9 +86,9 @@ func registerTemplateVars(c *Catalog, m *Message) error {
|
||||
// Render completes the Renderer interface.
|
||||
// It renders a template message.
|
||||
// Each key has its own Template, plurals too.
|
||||
func (t *Template) Render(args ...interface{}) (string, error) {
|
||||
func (t *Template) Render(args ...any) (string, error) {
|
||||
var (
|
||||
data interface{}
|
||||
data any
|
||||
result string
|
||||
)
|
||||
|
||||
@@ -125,7 +125,7 @@ func (t *Template) Render(args ...interface{}) (string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func findVarsCount(data interface{}, vars []Var) (args []interface{}) {
|
||||
func findVarsCount(data any, vars []Var) (args []any) {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -167,7 +167,7 @@ func findVarsCount(data interface{}, vars []Var) (args []interface{}) {
|
||||
return
|
||||
}
|
||||
|
||||
func findPluralCount(data interface{}) (int, bool) {
|
||||
func findPluralCount(data any) (int, bool) {
|
||||
if data == nil {
|
||||
return -1, false
|
||||
}
|
||||
@@ -207,7 +207,7 @@ func findPluralCount(data interface{}) (int, bool) {
|
||||
return -1, false
|
||||
}
|
||||
|
||||
func (t *Template) replaceTmplVars(result string, args ...interface{}) string {
|
||||
func (t *Template) replaceTmplVars(result string, args ...any) string {
|
||||
varsKey := t.Key + "." + VarsKeySuffix
|
||||
translationVarsText := t.Locale.Printer.Sprintf(varsKey, args...)
|
||||
if translationVarsText != "" {
|
||||
|
||||
@@ -15,14 +15,14 @@ import (
|
||||
// This package requires the golang.org/x/text/message capabilities
|
||||
// only for the variables feature, the message itself's pluralization is managed by the package.
|
||||
type Var struct {
|
||||
Name string // Variable name, e.g. Name
|
||||
Literal string // Its literal is ${Name}
|
||||
Cases []interface{} // one:...,few:...,...
|
||||
Format string // defaults to "%d".
|
||||
Argth int // 1, 2, 3...
|
||||
Name string // Variable name, e.g. Name
|
||||
Literal string // Its literal is ${Name}
|
||||
Cases []any // one:...,few:...,...
|
||||
Format string // defaults to "%d".
|
||||
Argth int // 1, 2, 3...
|
||||
}
|
||||
|
||||
func getVars(loc *Locale, key string, src map[string]interface{}) []Var {
|
||||
func getVars(loc *Locale, key string, src map[string]any) []Var {
|
||||
if len(src) == 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func getVars(loc *Locale, key string, src map[string]interface{}) []Var {
|
||||
return nil
|
||||
}
|
||||
|
||||
varValue, ok := varsKey.([]interface{})
|
||||
varValue, ok := varsKey.([]any)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func getVars(loc *Locale, key string, src map[string]interface{}) []Var {
|
||||
vars := make([]Var, 0, len(varValue))
|
||||
|
||||
for _, v := range varValue {
|
||||
m, ok := v.(map[string]interface{})
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func getVars(loc *Locale, key string, src map[string]interface{}) []Var {
|
||||
for k, inner := range m {
|
||||
varFormat := "%d"
|
||||
|
||||
innerMap, ok := inner.(map[string]interface{})
|
||||
innerMap, ok := inner.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
@@ -141,10 +141,10 @@ func removeMsgVarsDuplicates(elements []catalog.Message) (result []catalog.Messa
|
||||
}
|
||||
*/
|
||||
|
||||
func getCases(loc *Locale, src map[string]interface{}) []interface{} {
|
||||
func getCases(loc *Locale, src map[string]any) []any {
|
||||
type PluralCase struct {
|
||||
Form PluralForm
|
||||
Value interface{}
|
||||
Value any
|
||||
}
|
||||
|
||||
pluralCases := make([]PluralCase, 0, len(src))
|
||||
@@ -170,7 +170,7 @@ func getCases(loc *Locale, src map[string]interface{}) []interface{} {
|
||||
return left.Less(right)
|
||||
})
|
||||
|
||||
cases := make([]interface{}, 0, len(pluralCases)*2)
|
||||
cases := make([]any, 0, len(pluralCases)*2)
|
||||
for _, pluralCase := range pluralCases {
|
||||
// fmt.Printf("%s=%v\n", pluralCase.Form, pluralCase.Value)
|
||||
cases = append(cases, pluralCase.Form.String(), pluralCase.Value)
|
||||
|
||||
@@ -74,16 +74,16 @@ func FS(fileSystem fs.FS, pattern string, options LoaderConfig) (Loader, error)
|
||||
}
|
||||
|
||||
// LangMap key as language (e.g. "el-GR") and value as a map of key-value pairs (e.g. "hello": "Γειά").
|
||||
type LangMap = map[string]map[string]interface{}
|
||||
type LangMap = map[string]map[string]any
|
||||
|
||||
// KV is a loader which accepts a map of language(key) and the available key-value pairs.
|
||||
// Example Code:
|
||||
//
|
||||
// m := i18n.LangMap{
|
||||
// "en-US": map[string]interface{}{
|
||||
// "en-US": map[string]any{
|
||||
// "hello": "Hello",
|
||||
// },
|
||||
// "el-GR": map[string]interface{}{
|
||||
// "el-GR": map[string]any{
|
||||
// "hello": "Γειά",
|
||||
// },
|
||||
// }
|
||||
@@ -100,7 +100,7 @@ func KV(langMap LangMap, opts ...LoaderConfig) Loader {
|
||||
}
|
||||
|
||||
languageIndexes := make([]int, 0, len(langMap))
|
||||
keyValuesMulti := make([]map[string]interface{}, 0, len(langMap))
|
||||
keyValuesMulti := make([]map[string]any, 0, len(langMap))
|
||||
|
||||
for languageName, pairs := range langMap {
|
||||
langIndex := parseLanguageName(m, languageName) // matches and adds the language tag to m.Languages.
|
||||
@@ -170,7 +170,7 @@ func load(assetNames []string, asset func(string) ([]byte, error), options Loade
|
||||
}
|
||||
|
||||
for langIndex, langFiles := range languageFiles {
|
||||
keyValues := make(map[string]interface{})
|
||||
keyValues := make(map[string]any)
|
||||
|
||||
for _, fileName := range langFiles {
|
||||
unmarshal := yaml.Unmarshal
|
||||
@@ -211,13 +211,13 @@ func load(assetNames []string, asset func(string) ([]byte, error), options Loade
|
||||
}
|
||||
}
|
||||
|
||||
func unmarshalINI(data []byte, v interface{}) error {
|
||||
func unmarshalINI(data []byte, v any) error {
|
||||
f, err := ini.Load(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := *v.(*map[string]interface{})
|
||||
m := *v.(*map[string]any)
|
||||
|
||||
// Includes the ini.DefaultSection which has the root keys too.
|
||||
// We don't have to iterate to each section to find the subsection,
|
||||
|
||||
Reference in New Issue
Block a user