Skip to content

Commit 77b4a7e

Browse files
committed
Fix and remove 14.5.md spaces
1 parent 599e359 commit 77b4a7e

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

zh/14.5.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ LangPath string //设置语言包所在位置
1414
```Go
1515

1616
func InitLang(){
17-
beego.Translation:=i18n.NewLocale()
18-
beego.Translation.LoadPath(beego.LangPath)
19-
beego.Translation.SetLocale(beego.Lang)
17+
beego.Translation:=i18n.NewLocale()
18+
beego.Translation.LoadPath(beego.LangPath)
19+
beego.Translation.SetLocale(beego.Lang)
2020
}
2121
```
2222
为了方便在模板中直接调用多语言包,我们设计了三个函数来处理响应的多语言:
@@ -66,54 +66,54 @@ func I18nMoney(args ...interface{}) string {
6666
1. 设置语言以及语言包所在位置,然后初始化i18n对象:
6767
```Go
6868

69-
beego.Lang = "zh"
70-
beego.LangPath = "views/lang"
71-
beego.InitLang()
69+
beego.Lang = "zh"
70+
beego.LangPath = "views/lang"
71+
beego.InitLang()
7272
```
7373
2. 设计多语言包
7474

7575
上面讲了如何初始化多语言包,现在设计多语言包,多语言包是json文件,如第十章介绍的一样,我们需要把设计的文件放在LangPath下面,例如zh.json或者en.json
7676
```json
7777

78-
# zh.json
78+
# zh.json
7979

80-
{
81-
"zh": {
82-
"submit": "提交",
83-
"create": "创建"
84-
}
85-
}
80+
{
81+
"zh": {
82+
"submit": "提交",
83+
"create": "创建"
84+
}
85+
}
8686

87-
#en.json
87+
#en.json
8888

89-
{
90-
"en": {
91-
"submit": "Submit",
92-
"create": "Create"
93-
}
94-
}
89+
{
90+
"en": {
91+
"submit": "Submit",
92+
"create": "Create"
93+
}
94+
}
9595
```
9696
3. 使用语言包
9797

9898
我们可以在controller中调用翻译获取响应的翻译语言,如下所示:
9999
```Go
100100

101-
func (this *MainController) Get() {
102-
this.Data["create"] = beego.Translation.Translate("create")
103-
this.TplNames = "index.tpl"
104-
}
101+
func (this *MainController) Get() {
102+
this.Data["create"] = beego.Translation.Translate("create")
103+
this.TplNames = "index.tpl"
104+
}
105105
```
106106
我们也可以在模板中直接调用响应的翻译函数:
107107
```Go
108108

109-
//直接文本翻译
110-
{{.create | Trans}}
109+
//直接文本翻译
110+
{{.create | Trans}}
111111

112-
//时间翻译
113-
{{.time | TransDate}}
112+
//时间翻译
113+
{{.time | TransDate}}
114114

115-
//货币翻译
116-
{{.money | TransMoney}}
115+
//货币翻译
116+
{{.money | TransMoney}}
117117
```
118118
## links
119119
* [目录](<preface.md>)

0 commit comments

Comments
 (0)