From 333be428c4f599586679a71c2da5dfcdecbeeb9c Mon Sep 17 00:00:00 2001 From: "Gerasimos (Makis) Maropoulos" Date: Thu, 10 Sep 2020 10:12:06 +0300 Subject: [PATCH] use jet v5.0.2 (no breaking changes) relative to: https://github.com/kataras/iris/pull/1616 --- HISTORY.md | 2 +- _examples/i18n/i18n-template/main.go | 13 ++++++++++--- _examples/i18n/i18n-template/main_test.go | 2 ++ go.mod | 2 +- i18n/loader.go | 6 ------ view/jet.go | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 55fa50bb..e97e58d8 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -539,7 +539,7 @@ var dirOpts = iris.DirOptions{ } ``` -- Update jet parser to v4.0.2, closes [#1551](https://github.com/kataras/iris/issues/1551). It contains two breaking changes by its author: +- Update jet parser to v5.0.2, closes [#1551](https://github.com/kataras/iris/issues/1551). It contains two breaking changes by its author: - Relative paths on `extends, import, include...` tmpl functions, e.g. `{{extends "../layouts/application.jet"}}` instead of `layouts/application.jet` - the new [jet.Ranger](https://github.com/CloudyKit/jet/pull/165) interface now requires a `ProvidesIndex() bool` method too - Example has been [updated](https://github.com/kataras/iris/tree/master/_examples/view/template_jet_0) diff --git a/_examples/i18n/i18n-template/main.go b/_examples/i18n/i18n-template/main.go index 2dd398a3..8b2c93ce 100644 --- a/_examples/i18n/i18n-template/main.go +++ b/_examples/i18n/i18n-template/main.go @@ -10,7 +10,7 @@ import ( /* Iris I18n supports text/template inside the translation values. - Follow this tutorial to learn how to use that feature. + Follow this example to learn how to use that feature. */ func main() { @@ -31,8 +31,8 @@ func newApp() *iris.Application { // like we do here. // // Note that this is only for english, - // but you can accept the language code - // and use a map with dictionaries to + // but you can use the "current" locale + // and make a map with dictionaries to // pluralize words based on the given language. return pluralize.Pluralize(word, count, true) }, @@ -48,5 +48,12 @@ func newApp() *iris.Application { ctx.WriteString(text) }) + app.Get("/singular", func(ctx iris.Context) { + text := ctx.Tr("HiDogs", iris.Map{ + "count": 1, + }) // prints "Hi 1 dog". + ctx.WriteString(text) + }) + return app } diff --git a/_examples/i18n/i18n-template/main_test.go b/_examples/i18n/i18n-template/main_test.go index 2eca2fcd..0cc24db1 100644 --- a/_examples/i18n/i18n-template/main_test.go +++ b/_examples/i18n/i18n-template/main_test.go @@ -12,6 +12,8 @@ func TestI18nLoaderFuncMap(t *testing.T) { e := httptest.New(t, app) e.GET("/").Expect().Status(httptest.StatusOK). Body().Equal("Hi 2 dogs") + e.GET("/singular").Expect().Status(httptest.StatusOK). + Body().Equal("Hi 1 dog") e.GET("/").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK). Body().Equal("Γειά 2 σκυλί") } diff --git a/go.mod b/go.mod index bf739e1e..38c836d7 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398 github.com/andybalholm/brotli v1.0.1-0.20200619015827-c3da72aa01ed github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible - github.com/dgraph-io/badger/v2 v2.2007.1 + github.com/dgraph-io/badger/v2 v2.2007.2 github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 github.com/fatih/structs v1.1.0 github.com/gomodule/redigo v1.8.2 diff --git a/i18n/loader.go b/i18n/loader.go index 2cd581a0..948fb8fa 100644 --- a/i18n/loader.go +++ b/i18n/loader.go @@ -7,7 +7,6 @@ import ( "io/ioutil" "path/filepath" "strings" - "sync" "text/template" "github.com/kataras/iris/v12/context" @@ -266,11 +265,6 @@ type defaultLocale struct { defaultMessageFunc MessageFunc } -type templateKey struct { - Template *template.Template - once *sync.Once -} - func (l *defaultLocale) Index() int { return l.index } diff --git a/view/jet.go b/view/jet.go index d8fa74bd..b519bc46 100644 --- a/view/jet.go +++ b/view/jet.go @@ -11,7 +11,7 @@ import ( "github.com/kataras/iris/v12/context" - "github.com/CloudyKit/jet/v4" + "github.com/CloudyKit/jet/v5" ) const jetEngineName = "jet"