From 2b20c77bc0ecae42820dc7fc67c7bdbec1398307 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 15 Sep 2019 13:47:44 +0800 Subject: [PATCH] improve example for gi18n --- .example/i18n/gi18n/gi18n.go | 11 +++++++++++ .example/i18n/gi18n/http_view_i18n.go | 4 ++-- i18n/gi18n/gi18n_manager.go | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/.example/i18n/gi18n/gi18n.go b/.example/i18n/gi18n/gi18n.go index 5387a4f23..5787c6481 100644 --- a/.example/i18n/gi18n/gi18n.go +++ b/.example/i18n/gi18n/gi18n.go @@ -8,8 +8,19 @@ import ( func main() { t := gi18n.New() + t.SetPath("/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/i18n/gi18n/i18n") + t.SetLanguage("en") + fmt.Println(t.Translate(`hello`)) + fmt.Println(t.Translate(`{#hello}{#world}!`)) + t.SetLanguage("ja") fmt.Println(t.Translate(`hello`)) fmt.Println(t.Translate(`{#hello}{#world}!`)) + t.SetLanguage("ru") + fmt.Println(t.Translate(`hello`)) + fmt.Println(t.Translate(`{#hello}{#world}!`)) + + fmt.Println(t.Translate(`hello`, "zh-CN")) + fmt.Println(t.Translate(`{#hello}{#world}!`, "zh-CN")) } diff --git a/.example/i18n/gi18n/http_view_i18n.go b/.example/i18n/gi18n/http_view_i18n.go index dcfda67cb..ca5956c7b 100644 --- a/.example/i18n/gi18n/http_view_i18n.go +++ b/.example/i18n/gi18n/http_view_i18n.go @@ -9,8 +9,8 @@ func main() { g.I18n().SetPath("/Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/.example/i18n/gi18n/i18n") s := g.Server() s.BindHandler("/", func(r *ghttp.Request) { - r.Response.WriteTplContent(`{#hello}{#world}`, g.Map{ - "I18nLanguage": r.Get("lang", "en"), + r.Response.WriteTplContent(`{#hello}{#world}!`, g.Map{ + "I18nLanguage": r.Get("lang", "zh-CN"), }) }) s.SetPort(8199) diff --git a/i18n/gi18n/gi18n_manager.go b/i18n/gi18n/gi18n_manager.go index e1738dca1..4a2a4f1a2 100644 --- a/i18n/gi18n/gi18n_manager.go +++ b/i18n/gi18n/gi18n_manager.go @@ -179,7 +179,7 @@ func (m *Manager) init() { } } } - } else { + } else if m.options.Path != "" { files, _ := gfile.ScanDirFile(m.options.Path, "*.*", true) if len(files) > 0 { var path string