mirror of
https://github.com/kataras/iris.git
synced 2026-01-04 10:47:20 +00:00
add LoadKV method on Iris.Application.I18N instance
This commit is contained in:
21
i18n/i18n.go
21
i18n/i18n.go
@@ -141,8 +141,8 @@ func (i *I18n) LoadAssets(assetNames func() []string, asset func(string) ([]byte
|
||||
return i.Reset(Assets(assetNames, asset, i.Loader), languages...)
|
||||
}
|
||||
|
||||
// LoadFS is a method shortcut to load files using `embed.FS` or `fs.FS` or
|
||||
// `http.FileSystem` or `string` (local directory).
|
||||
// LoadFS is a method shortcut to load files using
|
||||
// an `embed.FS` or `fs.FS` or `http.FileSystem` value.
|
||||
// The "pattern" is a classic glob pattern.
|
||||
//
|
||||
// See `New` and `FS` package-level functions for more.
|
||||
@@ -156,6 +156,13 @@ func (i *I18n) LoadFS(fileSystem fs.FS, pattern string, languages ...string) err
|
||||
return i.Reset(loader, languages...)
|
||||
}
|
||||
|
||||
// LoadKV is a method shortcut to load locales from a map of specified languages.
|
||||
// See `KV` package-level function for more.
|
||||
func (i *I18n) LoadKV(langMap LangMap, languages ...string) error {
|
||||
loader := KV(langMap, i.Loader)
|
||||
return i.Reset(loader, languages...)
|
||||
}
|
||||
|
||||
// Reset sets the locales loader and languages.
|
||||
// It is not meant to be used by users unless
|
||||
// a custom `Loader` must be used instead of the default one.
|
||||
@@ -300,6 +307,16 @@ func parsePath(m *Matcher, path string) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func parseLanguageName(m *Matcher, name string) int {
|
||||
if t, err := language.Parse(name); err == nil {
|
||||
if _, index, conf := m.MatchOrAdd(t); conf > language.Low {
|
||||
return index
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func reverseStrings(s []string) []string {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
|
||||
Reference in New Issue
Block a user