1 Star 0 Fork 0

aspnmy / i18n4go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
test_templated_strings.go 1.53 KB
一键复制 编辑 原始数据 按行查看 历史
package input_files
import (
"fmt"
"strings"
)
func Templated() string {
name := T("cruel")
myName := T("evil")
fmt.Println(T("Hello {{.Name}} world!", map[string]interface{}{"Name": name}))
fmt.Println(T("Hello {{.Name}} world!, bye from {{.MyName}}", map[string]interface{}{"Name": name, "MyName": myName}))
fmt.Println(T("Hello {{.Name}} world!", map[string]interface{}{"Name": T("Evil")}))
//These should not have a map[string]interface{}
fmt.Println(T("Hello {{Not complex}} world! I am"), name)
fmt.Println(T("Hello {{}}"), myName)
fmt.Println(T("Hello {{.Name}} world!", map[string]interface{}{"Name": strings.ToUpper(name)}))
fmt.Println(T("Hello {{.Name}} world!", map[string]interface{}{"Name": strings.ToUpper(T("Hi"))}))
fmt.Println(T("Hello {{.Name}} world! {{.Number}} times", map[string]interface{}{"Name": name, "Number": 10}))
fmt.Println(T("Hello {{.Name}} world! {{.Float}} times", map[string]interface{}{"Name": name, "Float": 10.0}))
fmt.Println(T("Hello {{.Name}} world!", map[string]interface{}{"Name": strings.ToUpper(T("Hello {{.Name}} world!", map[string]interface{}{"Name": strings.ToUpper(name)}))}))
type something struct {
}
foo := something{}
strz := []string{T("one"), T("two"), T("buckle my shoe")}
fmt.Println(T("Welp, that's a great {{.MyStruct}} how about a {{.Whatever}}", map[string]interface{}{"MyStruct": &foo, "Whatever": strz[2]}))
println(T("Hello {{.Name}} world!", map[string]interface{}{"Name": name}))
println(T("Hello {{.Name}} world! {{.Name}}", map[string]interface{}{"Name": name}))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Aodao/i18n4go.git
git@gitee.com:Aodao/i18n4go.git
Aodao
i18n4go
i18n4go
v0.1.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891