Skip to content

Commit 657f8ce

Browse files
author
reco_luan
committed
feat(vuepress-plugin-pagation): add internationalization
1 parent 9ffd819 commit 657f8ce

File tree

4 files changed

+72
-13
lines changed

4 files changed

+72
-13
lines changed

example/.vuepress/config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ module.exports = {
1919
locales: {
2020
'/': {
2121
recoLocales: {
22-
homeBlog: {
23-
article: '美文', // 默认 文章
24-
tag: '标识', // 默认 标签
25-
category: '类别', // 默认 分类
26-
friendLink: '友链' // 默认 友情链接
22+
pagation: {
23+
prev: '上壹頁',
24+
next: '下壹頁',
25+
go: '前往',
26+
jump: '跳轉至'
2727
}
2828
}
2929
}

packages/@vuepress-reco/vuepress-plugin-pagation/bin/Pagation.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class="jump"
66
v-show="currentPage > 1"
77
@click="goPrev"
8-
unselectable="on">Prev</span>
8+
unselectable="on">{{pagationLocales.prev}}</span>
99
<span
1010
v-show="efont"
1111
class="jump"
@@ -29,19 +29,21 @@
2929
<span
3030
class="jump"
3131
v-show="currentPage < pages"
32-
@click="goNext">Next</span>
33-
<span class="jumppoint">跳转到:</span>
32+
@click="goNext">{{pagationLocales.next}}</span>
33+
<span class="jumppoint">{{pagationLocales.jump}}</span>
3434
<span class="jumpinp">
3535
<input type="text" v-model="changePage">
3636
</span>
3737
<span
3838
class="jump gobtn"
39-
@click="jumpPage(changePage)">GO</span>
39+
@click="jumpPage(changePage)">{{pagationLocales.go}}</span>
4040
</div>
4141
</div>
4242
</template>
4343

4444
<script>
45+
import pagationLocales from './locales'
46+
4547
export default {
4648
data () {
4749
return {
@@ -55,7 +57,7 @@ export default {
5557
},
5658
perPage: {
5759
type: Number,
58-
default: 10
60+
default: 2
5961
},
6062
currentPage: {
6163
type: Number,
@@ -97,6 +99,9 @@ export default {
9799
left++
98100
}
99101
return ar
102+
},
103+
pagationLocales () {
104+
return pagationLocales(this)
100105
}
101106
},
102107
methods: {
@@ -179,5 +184,5 @@ export default {
179184
&.ellipsis
180185
padding: 0px 8px;
181186
&.jumppoint
182-
margin-left: 30px;
187+
margin: 0 10px 0 30px;
183188
</style>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const zhHans = {
2+
prev: '上一页',
3+
next: '下一页',
4+
go: '前往',
5+
jump: '跳转至'
6+
}
7+
8+
const zhHant = {
9+
prev: '上壹頁',
10+
next: '下壹頁',
11+
go: '前往',
12+
jump: '跳轉至'
13+
}
14+
15+
const en = {
16+
prev: 'Prev',
17+
next: 'Next',
18+
go: 'Go',
19+
jump: 'Jump To'
20+
}
21+
22+
const ja = {
23+
prev: '前のページ',
24+
next: '次のページ',
25+
go: 'へ',
26+
jump: 'ジャンプ'
27+
}
28+
29+
const ko = {
30+
prev: '이전 페이지',
31+
next: '다음 페이지',
32+
go: '행',
33+
jump: '건너뛰기'
34+
}
35+
36+
export default function pagationLocales (ctx) {
37+
const { $lang, $recoLocales: { pagation }} = ctx
38+
if (pagation) {
39+
return pagation
40+
}
41+
if (/^zh\-(CN|SG)$/.test($lang)) {
42+
return zhHans
43+
}
44+
if (/^zh\-(HK|MO|TW)$/.test($lang)) {
45+
return zhHant
46+
}
47+
if (/^ja\-JP$/.test($lang)) {
48+
return ja
49+
}
50+
if (/^ko\-KR$/.test($lang)) {
51+
return ko
52+
}
53+
return en
54+
}

packages/vuepress-theme-reco/mixins/locales.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ export default {
44
computed: {
55
$recoLocales () {
66
const recoLocales = this.$themeLocaleConfig.recoLocales
7-
if (recoLocales) {
8-
return recoLocales
7+
if (recoLocales && recoLocales.homeBlog) {
8+
return { homeBlog: recoLocales.homeBlog }
99
}
1010
if (/^zh\-(CN|SG)$/.test(this.$lang)) {
1111
return zhHans

0 commit comments

Comments
 (0)