Skip to content

Commit 26f4d70

Browse files
committed
多语言OK
1 parent 1598978 commit 26f4d70

9 files changed

Lines changed: 290 additions & 150 deletions

File tree

.idea/workspace.xml

Lines changed: 156 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/js/locale.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const langContext = require.context('../lang/', false, /\.js$/)
2+
3+
let message = {}
4+
5+
let getName = (path)=>{
6+
return path.match(/([^\/]+)\.js$/)[1]
7+
}
8+
9+
langContext.keys().map((lang)=>{
10+
let name = getName(lang)
11+
message[name] = require('../lang/'+ name).default;
12+
})
13+
14+
export default message

src/common/js/tools.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import timeago from 'timeago.js'
22

33
export default {
44
timeagoFormat(time) {
5-
return timeago(null, 'zh_CN').format(time)
5+
let lang = navigator.language === 'zh-CN'?'zh-CN':'en-US';
6+
return timeago(null, lang).format(time)
67
},
78
installUserJs(uri) {
89
let link = parent.document.createElement("a");
910
link.href = uri;
1011
link.click();
1112
},
12-
msg(msg) {
13-
app.$Message.info(msg);
14-
},
1513
dispatchEvent(eventName) {
1614
parent.document.getElementById('jae_fetch_userjs').dispatchEvent(new Event(eventName))
1715
},

src/common/lang/en-US.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default {
2+
table:{
3+
tips: 'Found {count} user scripts for the current page',
4+
install: 'Install',
5+
title: 'Title',
6+
author: 'Suthor',
7+
authorTips: 'Click to access the {name} home page',
8+
dailyInstalls: 'Daily',
9+
updatedTime: 'Updated',
10+
action: 'Action',
11+
version: 'Version',
12+
score: 'Score',
13+
totalInstalls: 'Total Installs',
14+
description: 'Description',
15+
donate: 'Donate',
16+
wechat: 'Wechat',
17+
alipay: 'Alipay',
18+
paypal: 'PayPal',
19+
closeDonate: 'Close Donate',
20+
feedback: 'Feedback',
21+
close: 'No longer show'
22+
}
23+
}

src/common/lang/zh-CN.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default {
2+
table:{
3+
tips: '发现{count}个脚本适用于当前页面',
4+
install: '安装',
5+
title: '标题',
6+
author: '作者',
7+
authorTips: '点击访问{name}主页',
8+
dailyInstalls: '今日安装',
9+
updatedTime: '更新时间',
10+
action: '操作',
11+
version: '版本',
12+
score: '评分',
13+
totalInstalls: '总安装量',
14+
description: '描述',
15+
donate: '打赏',
16+
wechat: '微信',
17+
alipay: '支付宝',
18+
paypal: 'PayPal',
19+
closeDonate: '关闭打赏',
20+
feedback: '反馈',
21+
close: '该网站本次会话的所有页面都不再显示'
22+
}
23+
}

src/components/Info.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
<div>
33
<Row style="margin-bottom: 16px;">
44
<Col span="8">
5-
<span class="expand-key">版本:</span>
5+
<span class="expand-key">{{$t('table.version')}}:</span>
66
<span class="expand-value">{{ row.version }}</span>
77
</Col>
88
<Col span="8">
9-
<span class="expand-key">评分:</span>
9+
<span class="expand-key">{{$t('table.score')}}:</span>
1010
<span class="expand-value">{{ row.fan_score }}</span>
1111
</Col>
1212
<Col span="8">
13-
<span class="expand-key">总安装量:</span>
13+
<span class="expand-key">{{$t('table.totalInstalls')}}:</span>
1414
<span class="expand-value">{{ row.total_installs }}</span>
1515
</Col>
1616
</Row>
1717
<Row>
1818
<Col span="24">
19-
<span class="expand-key">描述:</span>
19+
<span class="expand-key">{{$t('table.description')}}:</span>
2020
<span class="expand-value">{{ row.description }}</span>
2121
</Col>
2222
</Row>

src/components/Table.vue

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,44 @@
33
<Card :padding="0">
44
<div slot="title" @click="bodySwitch" class="card-title">
55
<Icon :type="titleIcon"></Icon>
6-
<span>发现 <Badge :count="count"></Badge> 个脚本适用于当前页面</span>
6+
<!--<span>发现 <Badge :count="count"></Badge> 个脚本适用于当前页面</span>-->
7+
<i18n path="table.tips" tag="span">
8+
<Badge place="count" :count="count"></Badge>
9+
</i18n>
710
</div>
811
<div slot="extra">
912
<span v-show="showBody">
10-
<Button type="dashed" @click="open('https://greasyfork.org/zh-CN/scripts/24508/feedback')">
11-
<Icon type="bug"></Icon>
12-
</Button>
13+
<Tooltip :content="$t('table.feedback')" placement="bottom">
14+
<Button type="dashed" @click="open('https://greasyfork.org/zh-CN/scripts/24508/feedback')">
15+
<Icon type="bug"></Icon>
16+
</Button>
17+
</Tooltip>
1318

14-
<Button type="dashed" @click="open('https://greasyfork.org/zh-CN/scripts/24508')">
15-
<Icon type="fork"></Icon>
16-
</Button>
19+
<Tooltip content="GreasyFork" placement="bottom">
20+
<Button type="dashed" @click="open('https://greasyfork.org/zh-CN/scripts/24508')">
21+
<Icon type="fork"></Icon>
22+
</Button>
23+
</Tooltip>
1724

18-
<Button type="dashed" @click="open('https://github.com/jae-jae/Show-Site-All-UserJS')">
19-
<Icon type="social-github"></Icon>
20-
</Button>
25+
<Tooltip content="GitHub" placement="bottom">
26+
<Button type="dashed" @click="open('https://github.com/jae-jae/Show-Site-All-UserJS')">
27+
<Icon type="social-github"></Icon>
28+
</Button>
29+
</Tooltip>
2130

22-
<Button type="dashed" @click="showDonate = true">
23-
<Icon type="card"></Icon>
24-
</Button>
31+
<Tooltip :content="$t('table.donate')" placement="bottom">
32+
<Button type="dashed" @click="showDonate = true">
33+
<Icon type="card"></Icon>
34+
</Button>
35+
</Tooltip>
2536
</span>
26-
<Button type="dashed" @click="close">
27-
<Icon type="close-round"></Icon>
28-
</Button>
37+
38+
<Tooltip :content="$t('table.close')" placement="left">
39+
<Button type="dashed" @click="close">
40+
<Icon type="close-round"></Icon>
41+
</Button>
42+
</Tooltip>
43+
2944
</div>
3045
<transition name="custom-classes-transition" enter-active-class="animated jello" leave-active-class="animated bounceOutRight">
3146
<div v-show="showBody">
@@ -37,19 +52,19 @@
3752

3853
<Tabs value="wechat">
3954

40-
<Tab-Pane label="微信打赏" name="wechat">
55+
<Tab-Pane :label="$t('table.wechat')" name="wechat">
4156
<div style="text-align: center;">
4257
<img width="200px" src="http://ww1.sinaimg.cn/large/7de3675bly1fizyy2pivwj2074074js6.jpg">
4358
</div>
4459
</Tab-Pane>
4560

46-
<Tab-Pane label="支付宝打赏" name="alipay">
61+
<Tab-Pane :label="$t('table.alipay')" name="alipay">
4762
<div style="text-align: center;">
4863
<img width="200px" src="http://ww1.sinaimg.cn/large/7de3675bly1fizyyh7m7yj20ci0ciwfl.jpg">
4964
</div>
5065
</Tab-Pane>
5166

52-
<Tab-Pane label="PayPal打赏" name="paypal">
67+
<Tab-Pane :label="$t('table.paypal')" name="paypal">
5368
<div style="text-align: center;">
5469
<a href="https://paypal.me/jaepay/10" target="_blank">
5570
<img src="http://ww1.sinaimg.cn/large/7de3675bly1fizzsw92owj207s03s748.jpg">
@@ -60,7 +75,7 @@
6075
</Tabs>
6176

6277
<div slot="footer">
63-
<Button type="info" size="large" long @click="showDonate=false">关闭</Button>
78+
<Button type="info" size="large" long @click="showDonate=false">{{$t('table.closeDonate')}}</Button>
6479
</div>
6580

6681
</Modal>
@@ -70,6 +85,7 @@
7085
<script>
7186
import Tools from '../common/js/tools'
7287
import Info from './Info.vue'
88+
import Vue from 'vue'
7389
export default {
7490
components: { Info },
7591
mounted: function() {
@@ -83,7 +99,7 @@
8399
})*/
84100
this.data = Tools.getData()
85101
},
86-
data: ()=>{
102+
data: function (){
87103
return {
88104
showBody: false,
89105
titleIcon: 'chevron-up',
@@ -107,7 +123,7 @@
107123
align: 'center'
108124
},
109125
{
110-
title: '标题',
126+
title: this.$t('table.title'),
111127
key: 'name',
112128
width: '35%',
113129
ellipsis: false,
@@ -128,11 +144,11 @@
128144
}
129145
},
130146
{
131-
title: '作者',
147+
title: this.$t('table.author'),
132148
render: (h, params) => {
133149
return h('span', {
134150
attrs: {
135-
title: `点击访问${params.row.user.name}主页`
151+
title:this.$t('table.authorTips',{name:params.row.user.name})
136152
},
137153
style: {
138154
cursor: 'pointer'
@@ -146,20 +162,20 @@
146162
}
147163
},
148164
{
149-
title: '今日安装',
165+
title: this.$t('table.dailyInstalls'),
150166
key: 'daily_installs',
151167
sortable: true
152168
},
153169
{
154-
title: '更新时间',
170+
title: this.$t('table.updatedTime'),
155171
key: 'code_updated_at',
156172
render: (h, params) => {
157173
return h('span', Tools.timeagoFormat(params.row.code_updated_at))
158174
},
159175
sortable: true
160176
},
161177
{
162-
title: '操作',
178+
title: this.$t('table.action'),
163179
key: 'code_url',
164180
align: 'center',
165181
render: (h, params) => {
@@ -175,11 +191,12 @@
175191
},
176192
on: {
177193
click: (event) => {
178-
Tools.msg('脚本安装中...')
194+
//Tools.msg('脚本安装中...')
195+
this.$Message.info('脚本安装中...');
179196
Tools.installUserJs(params.row.code_url)
180197
}
181198
}
182-
}, '安装')
199+
}, this.$t('table.install'))
183200
])
184201
}
185202
}

src/main.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,30 @@ import App from './App.vue'
33
import iView from 'iview';
44
import 'iview/dist/styles/iview.css'; // 使用 CSS
55
import 'animate.css'
6+
import VueI18n from 'vue-i18n'
7+
import localeMessage from './common/js/locale'
8+
9+
console.log(localeMessage)
10+
11+
Vue.locale = (locale) => {
12+
13+
};
14+
15+
Vue.use(VueI18n)
16+
17+
Vue.use(iView)
18+
19+
const i18n = new VueI18n({
20+
//locale: navigator.language, // 语言标识
21+
locale: 'en-US',
22+
messages: localeMessage
23+
})
624

7-
Vue.use(iView);
825

926
let appEl = window.document.getElementById('app')
1027

11-
window.app = new Vue({
28+
new Vue({
29+
i18n,
1230
el: appEl,
1331
render: h => h(App)
1432
})

src/user.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ var inline_src = (<><![CDATA[
4040
this.showTime = 10;
4141
this.quietKey = 'jae_fetch_userjs_quiet';
4242
this.cacheKey = 'jae_fetch_userjs_cache';
43-
this.tplBox = '<div id="jae_fetch_userjs_wrapper"><style> #jae_fetch_userjs { position: fixed; width: 350px; bottom: 10px; right: 20px; z-index: 9999; height: 51px;box-shadow: 0px 1px 4px rgba(0,0,0,0.3),\t\t\t\t0px 0px 20px rgba(0,0,0,0.1) inset; }#jae_fetch_userjs::before,#jae_fetch_userjs::after { content:""; position:absolute; z-index:-1;}#jae_fetch_userjs::before,#jae_fetch_userjs::after { content:""; position:absolute; z-index:-1; bottom:15px; left:10px; width:50%; height:20%;}#jae_fetch_userjs::before,#jae_fetch_userjs::after { content:""; position:absolute; z-index:-1; bottom:15px; left:10px; width:50%; height:20%; box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); transform:rotate(-3deg);}#jae_fetch_userjs::after{ right:10px; left:auto; transform:rotate(3deg); }</style><div id="jae_fetch_userjs" class=""></div></div>';
43+
this.tplBox = '<div id="jae_fetch_userjs_wrapper"><style> #jae_fetch_userjs { position: fixed; width: 370px; bottom: 10px; right: 20px; z-index: 9999999999; height: 51px;box-shadow: 0px 1px 4px rgba(0,0,0,0.3),\t\t\t\t0px 0px 20px rgba(0,0,0,0.1) inset; }#jae_fetch_userjs::before,#jae_fetch_userjs::after { content:""; position:absolute; z-index:-1;}#jae_fetch_userjs::before,#jae_fetch_userjs::after { content:""; position:absolute; z-index:-1; bottom:15px; left:10px; width:50%; height:20%;}#jae_fetch_userjs::before,#jae_fetch_userjs::after { content:""; position:absolute; z-index:-1; bottom:15px; left:10px; width:50%; height:20%; box-shadow:0 15px 10px rgba(0, 0, 0, 0.7); transform:rotate(-3deg);}#jae_fetch_userjs::after{ right:10px; left:auto; transform:rotate(3deg); }</style><div id="jae_fetch_userjs" class=""></div></div>';
4444
}
4545

4646
getJSON(url,callback){
@@ -93,7 +93,7 @@ var inline_src = (<><![CDATA[
9393

9494
this.addEventListener('min',()=>{
9595
setTimeout(()=>{
96-
this.setSize(350,51)
96+
this.setSize(370,51)
9797
},800)
9898
})
9999

0 commit comments

Comments
 (0)