mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
// Copyright 2019 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gview_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/gogf/gf/debug/gdebug"
|
|
"github.com/gogf/gf/os/gfile"
|
|
|
|
"github.com/gogf/gf/frame/g"
|
|
"github.com/gogf/gf/test/gtest"
|
|
)
|
|
|
|
func Test_I18n(t *testing.T) {
|
|
gtest.Case(t, func() {
|
|
content := `{{.name}} says "{#hello}{#world}!"`
|
|
expect1 := `john says "你好世界!"`
|
|
expect2 := `john says "こんにちは世界!"`
|
|
expect3 := `john says "{#hello}{#world}!"`
|
|
|
|
g.I18n().SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n")
|
|
|
|
g.I18n().SetLanguage("zh-CN")
|
|
result1, err := g.View().ParseContent(content, g.Map{
|
|
"name": "john",
|
|
})
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(result1, expect1)
|
|
|
|
g.I18n().SetLanguage("ja")
|
|
result2, err := g.View().ParseContent(content, g.Map{
|
|
"name": "john",
|
|
})
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(result2, expect2)
|
|
|
|
g.I18n().SetLanguage("none")
|
|
result3, err := g.View().ParseContent(content, g.Map{
|
|
"name": "john",
|
|
})
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(result3, expect3)
|
|
})
|
|
gtest.Case(t, func() {
|
|
content := `{{.name}} says "{#hello}{#world}!"`
|
|
expect1 := `john says "你好世界!"`
|
|
expect2 := `john says "こんにちは世界!"`
|
|
expect3 := `john says "{#hello}{#world}!"`
|
|
|
|
g.I18n().SetPath(gdebug.CallerDirectory() + gfile.Separator + "testdata" + gfile.Separator + "i18n")
|
|
|
|
result1, err := g.View().ParseContent(content, g.Map{
|
|
"name": "john",
|
|
"I18nLanguage": "zh-CN",
|
|
})
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(result1, expect1)
|
|
|
|
result2, err := g.View().ParseContent(content, g.Map{
|
|
"name": "john",
|
|
"I18nLanguage": "ja",
|
|
})
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(result2, expect2)
|
|
|
|
result3, err := g.View().ParseContent(content, g.Map{
|
|
"name": "john",
|
|
"I18nLanguage": "none",
|
|
})
|
|
gtest.Assert(err, nil)
|
|
gtest.Assert(result3, expect3)
|
|
})
|
|
}
|