Fix and remove 14.5.md spaces
This commit is contained in:
60
zh/14.5.md
60
zh/14.5.md
@@ -14,9 +14,9 @@ LangPath string //设置语言包所在位置
|
|||||||
```Go
|
```Go
|
||||||
|
|
||||||
func InitLang(){
|
func InitLang(){
|
||||||
beego.Translation:=i18n.NewLocale()
|
beego.Translation:=i18n.NewLocale()
|
||||||
beego.Translation.LoadPath(beego.LangPath)
|
beego.Translation.LoadPath(beego.LangPath)
|
||||||
beego.Translation.SetLocale(beego.Lang)
|
beego.Translation.SetLocale(beego.Lang)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
为了方便在模板中直接调用多语言包,我们设计了三个函数来处理响应的多语言:
|
为了方便在模板中直接调用多语言包,我们设计了三个函数来处理响应的多语言:
|
||||||
@@ -66,54 +66,54 @@ func I18nMoney(args ...interface{}) string {
|
|||||||
1. 设置语言以及语言包所在位置,然后初始化i18n对象:
|
1. 设置语言以及语言包所在位置,然后初始化i18n对象:
|
||||||
```Go
|
```Go
|
||||||
|
|
||||||
beego.Lang = "zh"
|
beego.Lang = "zh"
|
||||||
beego.LangPath = "views/lang"
|
beego.LangPath = "views/lang"
|
||||||
beego.InitLang()
|
beego.InitLang()
|
||||||
```
|
```
|
||||||
2. 设计多语言包
|
2. 设计多语言包
|
||||||
|
|
||||||
上面讲了如何初始化多语言包,现在设计多语言包,多语言包是json文件,如第十章介绍的一样,我们需要把设计的文件放在LangPath下面,例如zh.json或者en.json
|
上面讲了如何初始化多语言包,现在设计多语言包,多语言包是json文件,如第十章介绍的一样,我们需要把设计的文件放在LangPath下面,例如zh.json或者en.json
|
||||||
```json
|
```json
|
||||||
|
|
||||||
# zh.json
|
# zh.json
|
||||||
|
|
||||||
{
|
{
|
||||||
"zh": {
|
"zh": {
|
||||||
"submit": "提交",
|
"submit": "提交",
|
||||||
"create": "创建"
|
"create": "创建"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#en.json
|
#en.json
|
||||||
|
|
||||||
{
|
{
|
||||||
"en": {
|
"en": {
|
||||||
"submit": "Submit",
|
"submit": "Submit",
|
||||||
"create": "Create"
|
"create": "Create"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
3. 使用语言包
|
3. 使用语言包
|
||||||
|
|
||||||
我们可以在controller中调用翻译获取响应的翻译语言,如下所示:
|
我们可以在controller中调用翻译获取响应的翻译语言,如下所示:
|
||||||
```Go
|
```Go
|
||||||
|
|
||||||
func (this *MainController) Get() {
|
func (this *MainController) Get() {
|
||||||
this.Data["create"] = beego.Translation.Translate("create")
|
this.Data["create"] = beego.Translation.Translate("create")
|
||||||
this.TplNames = "index.tpl"
|
this.TplNames = "index.tpl"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
我们也可以在模板中直接调用响应的翻译函数:
|
我们也可以在模板中直接调用响应的翻译函数:
|
||||||
```Go
|
```Go
|
||||||
|
|
||||||
//直接文本翻译
|
//直接文本翻译
|
||||||
{{.create | Trans}}
|
{{.create | Trans}}
|
||||||
|
|
||||||
//时间翻译
|
//时间翻译
|
||||||
{{.time | TransDate}}
|
{{.time | TransDate}}
|
||||||
|
|
||||||
//货币翻译
|
//货币翻译
|
||||||
{{.money | TransMoney}}
|
{{.money | TransMoney}}
|
||||||
```
|
```
|
||||||
## links
|
## links
|
||||||
* [目录](<preface.md>)
|
* [目录](<preface.md>)
|
||||||
|
|||||||
Reference in New Issue
Block a user