Skip to content

Commit c14d380

Browse files
committed
Recode locale messages with typescript
1 parent e3dc797 commit c14d380

File tree

18 files changed

+365
-139
lines changed

18 files changed

+365
-139
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
language: node_js
33
node_js:
4-
- 14
4+
- 16
55
install:
66
- npm install
77
- npm install -g jest

src/common/element-plus.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Process locale
2-
import { locale, Locale } from '../common/vue-i18n'
2+
import { locale } from '../common/vue-i18n'
33
import zhLocale from 'element-plus/lib/locale/lang/zh-cn'
44
import enLang from 'element-plus/lib/locale/lang/en'
55
import { locale as eleLocale } from 'element-plus'
6+
import { Locale } from '../locale/constant'
67

78
if (locale === Locale.EN) {
89
eleLocale(enLang)

src/common/vue-i18n.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import { VNode } from 'vue'
2-
import { vueMessages, defaultLocale } from '../locale'
3-
4-
export enum Locale {
5-
ZH_CN = 'zh_CN',
6-
EN = 'en'
7-
}
2+
import messages from '../locale'
3+
import { defaultLocale, Locale } from '../locale/constant'
84

95
// Standardize the locale code according to the Chrome locale code
106
const chrome2I18n: { [key: string]: Locale } = {
117
'zh-CN': Locale.ZH_CN,
128
'zh-TW': Locale.ZH_CN,
139
'en-US': Locale.EN,
14-
'en-GB': Locale.EN
10+
'en-GB': Locale.EN,
11+
'ja': Locale.JA
1512
}
1613

1714
/**
@@ -31,7 +28,7 @@ const chromeLocale2ExtensionLocale = (chromeLocale: string) => {
3128

3229
export const locale = chromeLocale2ExtensionLocale(chrome.i18n.getUILanguage())
3330

34-
const message: any = vueMessages[locale] || {}
31+
const message: any = messages[locale] || {}
3532

3633
export declare type I18nResultItem = VNode | string
3734

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type AppMessage = {
4+
name: string
5+
marketName: string
6+
description: string
7+
currentVersion: string
8+
}
9+
10+
const _default: Messages<AppMessage> = {
211
en: {
312
name: 'Timer',
413
marketName: 'Timer - Running & Browsing Time & Visit count',
@@ -17,4 +26,6 @@ module.exports = {
1726
description: '最高のオンライン時間統計ツールを作成します。',
1827
currentVersion: 'バージョン: v{version}'
1928
}
20-
}
29+
}
30+
31+
export default _default
Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type ClearMessage = {
4+
totalMemoryAlert: string
5+
usedMemoryAlert: string
6+
operationAlert: string
7+
filterItems: string
8+
filterFocus: string
9+
filterTotal: string
10+
filterTime: string
11+
filterDate: string
12+
unlimited: string
13+
archiveAlert: string
14+
dateShortcut: {
15+
tillYesturday: string
16+
till7DaysAgo: string
17+
till30DaysAgo: string
18+
}
19+
paramError: string
20+
deleteConfirm: string
21+
deleteSuccess: string
22+
archiveConfirm: string
23+
archiveSuccess: string
24+
}
25+
26+
const _default: Messages<ClearMessage> = {
227
zh_CN: {
328
totalMemoryAlert: '浏览器为每个扩展提供 {size}MB 来存储本地数据',
429
usedMemoryAlert: '当前已使用 {size}MB',
@@ -27,7 +52,7 @@ module.exports = {
2752
operationAlert: 'You can archive or delete those irrelevant data to reduce memory usage',
2853
filterItems: 'Filter data',
2954
filterFocus: 'The browse time of the day is between {start} seconds and {end} seconds.',
30-
filterFocus: 'The run time of the day is between {start} seconds and {end} seconds.',
55+
filterTotal: 'The run time of the day is between {start} seconds and {end} seconds.',
3156
filterTime: 'Opens on the day are between {start} and {end}.',
3257
filterDate: 'Generated between {picker}.',
3358
unlimited: 'Unlimited',
@@ -65,4 +90,6 @@ module.exports = {
6590
archiveConfirm: '合計 {count} 個のデータが除外されました。それらはすべてアーカイブされていますか?',
6691
archiveSuccess: '正常にアーカイブされました'
6792
}
68-
}
93+
}
94+
95+
export default _default
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,26 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type ItemMessage = {
4+
date: string
5+
host: string
6+
total: string
7+
focus: string
8+
time: string
9+
operation: {
10+
label: string
11+
delete: string
12+
add2Whitelist: string
13+
removeFromWhitelist: string
14+
archive: string
15+
confirmMsg: string
16+
cancelMsg: string
17+
deleteConfirmMsgAll: string
18+
deleteConfirmMsgRange: string
19+
deleteConfirmMsg: string
20+
}
21+
}
22+
23+
const _default: Messages<ItemMessage> = {
224
zh_CN: {
325
date: '日期',
426
host: '域名',
@@ -56,4 +78,6 @@ module.exports = {
5678
deleteConfirmMsg: '{date} の {url} の訪問記録は削除されます'
5779
}
5880
}
59-
}
81+
}
82+
83+
export default _default
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type MenuMessage = {
4+
data: string
5+
dataReport: string
6+
dataHistory: string
7+
dataClear: string
8+
setting: string
9+
}
10+
const _default: Messages<MenuMessage> = {
211
zh_CN: {
312
data: '我的数据',
413
dataReport: '报表明细',
@@ -20,4 +29,6 @@ module.exports = {
2029
dataClear: '記憶状況',
2130
setting: '拡張設定',
2231
}
23-
}
32+
}
33+
34+
export default _default
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type MsgMessage = {
4+
openTimesConsoleLog: string
5+
usedTimeInConsoleLog: string
6+
timeWithHour: string
7+
timeWithMinute: string
8+
timeWithSecond: string
9+
}
10+
const _default: Messages<MsgMessage> = {
211
zh_CN: {
312
openTimesConsoleLog: '今天您打开了 {time} 次 {host}。',
413
usedTimeInConsoleLog: '它今天在您的电脑上运行了 {total},其中您花费了 {focus}来浏览它。',
514
timeWithHour: '{hour} 小时 {minute} 分 {second} 秒',
615
timeWithMinute: '{minute} 分 {second} 秒',
716
timeWithSecond: '{second} 秒',
8-
updateNotification: '版本已更新,需要您授权将新功能应用到所有页面。',
9-
updateNotificationForFirefox: '版本已更新,你需要重启浏览器来适应新功能。',
10-
notificationGrant: '授权'
17+
1118
},
1219
en: {
1320
openTimesConsoleLog: 'You have open {host} for {time} time(s) today.',
1421
usedTimeInConsoleLog: 'And it rans on your PC for {total} today, and is browsed for {focus}.',
1522
timeWithHour: '{hour} hour(s) {minute} minute(s) {second} second(s)',
1623
timeWithMinute: '{minute} minute(s) {second} second(s)',
1724
timeWithSecond: '{second} second(s)',
18-
updateNotification: 'The extension updated and requires authorization to apply the new features to all pages.',
19-
updateNotificationForFirefox: 'The extension updated and requires relaunch to apply the new features to all pages.',
20-
notificationGrant: 'OK, I GRANT'
2125
},
2226
ja: {
2327
openTimesConsoleLog: '今日、あなたは {host} を {time} 回開きました。',
2428
usedTimeInConsoleLog: 'それは今日あなたのコンピュータで {total} 実行されました、そのうちあなたはそれを閲覧するために {focus} を費やしました。',
2529
timeWithHour: '{hour} 時間 {minute} 分 {second} 秒',
2630
timeWithMinute: '{minute} 分 {second} 秒',
2731
timeWithSecond: '{second} 秒',
28-
updateNotification: 'バージョンが更新されており、すべてのページに新機能を適用するには承認が必要です。',
29-
updateNotificationForFirefox: 'バージョンが更新されました。新しい機能に適応するには、ブラウザを再起動する必要があります。',
30-
notificationGrant: '承認'
3132
}
32-
}
33+
}
34+
35+
export default _default
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type PopupMessage = {
4+
title: string
5+
mergeDomainLabel: string
6+
viewMore: string
7+
fileName: string
8+
saveAsImageTitle: string
9+
totalTime: string
10+
totalCount: string
11+
otherLabel: string
12+
}
13+
const _default: Messages<PopupMessage> = {
214
zh_CN: {
315
title: '今日数据',
416
mergeDomainLabel: '合并子域名',
@@ -29,4 +41,6 @@ module.exports = {
2941
totalCount: '合計 {totalCount} 回',
3042
otherLabel: 'その他'
3143
}
32-
}
44+
}
45+
46+
export default _default
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
module.exports = {
1+
import { Messages } from "../constant"
2+
3+
export type ReportMessage = {
4+
title: string
5+
startDate: string
6+
endDate: string
7+
latestWeek: string
8+
latest30Days: string
9+
today: string
10+
yesterday: string
11+
mergeDate: string
12+
mergeDomain: string
13+
displayBySecond: string
14+
hostPlaceholder: string
15+
exportFileName: string
16+
added2Whitelist: string
17+
removeFromWhitelist: string
18+
}
19+
20+
const _default: Messages<ReportMessage> = {
221
zh_CN: {
322
title: '数据统计',
423
startDate: '开始日期',
@@ -47,4 +66,6 @@ module.exports = {
4766
added2Whitelist: 'ホワイトリストに正常に追加されました',
4867
removeFromWhitelist: 'ホワイトリストから正常に削除されました'
4968
}
50-
}
69+
}
70+
71+
export default _default

0 commit comments

Comments
 (0)