1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-25 21:05:56 +00:00

i18n: expose the LoaderConfig from the main i18n instance and add an example

Signed-off-by: Gerasimos (Makis) Maropoulos <kataras2006@hotmail.com>
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-10 05:17:03 +03:00
parent b77227a0f9
commit 777ef0cd3e
8 changed files with 134 additions and 23 deletions

View File

@@ -49,6 +49,7 @@ type I18n struct {
localizer Localizer
matcher *Matcher
Loader *LoaderConfig
loader Loader
mu sync.Mutex
@@ -106,11 +107,18 @@ func makeTags(languages ...string) (tags []language.Tag) {
// New returns a new `I18n` instance. Use its `Load` or `LoadAssets` to load languages.
func New() *I18n {
return &I18n{
i := &I18n{
Loader: &LoaderConfig{
Left: "{{",
Right: "}}",
Strict: false,
},
URLParameter: "lang",
Subdomain: true,
PathRedirect: true,
}
return i
}
// Load is a method shortcut to load files using a filepath.Glob pattern.
@@ -118,7 +126,7 @@ func New() *I18n {
//
// See `New` and `Glob` package-level functions for more.
func (i *I18n) Load(globPattern string, languages ...string) error {
return i.Reset(Glob(globPattern), languages...)
return i.Reset(Glob(globPattern, i.Loader), languages...)
}
// LoadAssets is a method shortcut to load files using go-bindata.
@@ -126,7 +134,7 @@ func (i *I18n) Load(globPattern string, languages ...string) error {
//
// See `New` and `Asset` package-level functions for more.
func (i *I18n) LoadAssets(assetNames func() []string, asset func(string) ([]byte, error), languages ...string) error {
return i.Reset(Assets(assetNames, asset), languages...)
return i.Reset(Assets(assetNames, asset, i.Loader), languages...)
}
// Reset sets the locales loader and languages.