Merge branch 'master' of https://github.com/astaxie/build-web-application-with-golang
Conflicts: 2.2.md 2.3.md genepub.sh
This commit is contained in:
29
10.3.md
29
10.3.md
@@ -5,23 +5,40 @@
|
|||||||
|
|
||||||
# zh.json
|
# zh.json
|
||||||
|
|
||||||
zh:
|
{
|
||||||
submit: '提交'
|
"zh": {
|
||||||
create: '创建'
|
"submit": "提交",
|
||||||
|
"create": "创建"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#en.json
|
#en.json
|
||||||
|
|
||||||
en:
|
{
|
||||||
submit: 'Submit'
|
"en": {
|
||||||
create: 'Create'
|
"submit": "Submit",
|
||||||
|
"create": "Create"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
然后调用go-i18n包里面注册一下这个目录,这样Go会加载config/locales目录下的locale文件:
|
然后调用go-i18n包里面注册一下这个目录,这样Go会加载config/locales目录下的locale文件:
|
||||||
|
|
||||||
Tr:=i18n.NewLocale()
|
Tr:=i18n.NewLocale()
|
||||||
Tr.LoadPath("config/locales")
|
Tr.LoadPath("config/locales")
|
||||||
|
|
||||||
|
使用很简单,你可以通过下面的方式进行测试:
|
||||||
|
|
||||||
|
fmt.Println(Tr.Translate("submit"))
|
||||||
|
//输出Submit
|
||||||
|
Tr.SetLocale("zn")
|
||||||
|
fmt.Println(Tr.Translate("submit"))
|
||||||
|
//输出“递交”
|
||||||
|
|
||||||
## 自动加载本地包
|
## 自动加载本地包
|
||||||
|
上面我们介绍了多个自定义语言包的自动加载,那么在我们加载的同时,其实go-i18n库会自动帮你加载一些定义的格式信息,例如时间格式、货币格式。请看下面的处理过程
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## template mapfunc
|
## template mapfunc
|
||||||
|
|
||||||
|
|||||||
2
2.2.md
2
2.2.md
@@ -238,7 +238,7 @@ Go之所以会那么简洁,是因为它有一些默认的行为:
|
|||||||
- 大写字母开头的变量是可导出的,也就是其它包可以读取的,是公用变量;小写字母开头的就是不可导出的,是私有变量。
|
- 大写字母开头的变量是可导出的,也就是其它包可以读取的,是公用变量;小写字母开头的就是不可导出的,是私有变量。
|
||||||
- 大写字母开头的函数也是一样,相当于`class`中的带`public`关键词的公有函数;小写字母开头的就是有`private`关键词的私有函数。
|
- 大写字母开头的函数也是一样,相当于`class`中的带`public`关键词的公有函数;小写字母开头的就是有`private`关键词的私有函数。
|
||||||
|
|
||||||
##array、slice和map
|
## array、slice、map
|
||||||
|
|
||||||
### array
|
### array
|
||||||
`array`就是数组,它的定义方式如下:
|
`array`就是数组,它的定义方式如下:
|
||||||
|
|||||||
14
genepub.sh
14
genepub.sh
@@ -3,15 +3,19 @@ if [ ! -f build-web-application-with-golang ];then
|
|||||||
go build
|
go build
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d tmp ];then
|
if [ ! -d html ];then
|
||||||
mkdir tmp
|
mkdir html
|
||||||
fi
|
fi
|
||||||
cd tmp
|
cd html
|
||||||
cp ../*.md .
|
cp ../*.md .
|
||||||
for i in *.md;do
|
for i in *.md;do
|
||||||
|
#<23><><EFBFBD>¸<EFBFBD>ʽ<EFBFBD><CABD>md<6D>ļ<EFBFBD>
|
||||||
sed -i '/^[#]\{1,\}/s!^\([#]\{1,\}\)\([^#]\{1,\}\)!\1 \2!' $i
|
sed -i '/^[#]\{1,\}/s!^\([#]\{1,\}\)\([^#]\{1,\}\)!\1 \2!' $i
|
||||||
|
sed -i '/^[#]\{1,\}/s! ! !' $i
|
||||||
|
#<23><><EFBFBD><EFBFBD>md<6D>ļ<EFBFBD><C4BC>е<EFBFBD>image src<72><63><EFBFBD><EFBFBD>
|
||||||
sed -i '/!\[\](images/s#images\(.*\)?raw=true#../Images\1#' $i
|
sed -i '/!\[\](images/s#images\(.*\)?raw=true#../Images\1#' $i
|
||||||
|
|
||||||
done
|
done
|
||||||
cd ../build-web-application-with-golang
|
../build-web-application-with-golang >/dev/null
|
||||||
rm -rf *.md
|
rm *.md
|
||||||
|
echo "<22>ļ<EFBFBD><C4BC>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>sigil<69><6C><EFBFBD><EFBFBD>htmlĿ¼<C4BF>е<EFBFBD>html<6D>ļ<EFBFBD><C4BC><EFBFBD>imagesĿ¼<C4BF>е<EFBFBD>ͼƬ<CDBC>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>epub"
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 136 KiB After Width: | Height: | Size: 141 KiB |
Reference in New Issue
Block a user