-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18n.js
More file actions
168 lines (156 loc) · 3.46 KB
/
Copy pathi18n.js
File metadata and controls
168 lines (156 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'use strict';
/**
* i18n.js — 国际化模块
*
* 支持中文/英文双语切换
*/
const translations = {
zh: {
app: {
title: 'Alpha-Radar 行业情报引擎',
subtitle: 'Web3/Crypto 行业聚合 + AI 分类摘要 + 多渠道推送',
},
nav: {
home: '首页',
news: '情报',
stats: '统计',
settings: '设置',
},
news: {
title: '情报列表',
source: '来源',
category: '分类',
importance: '重要性',
publishedAt: '发布时间',
search: '搜索情报...',
noData: '暂无数据',
loadMore: '加载更多',
},
stats: {
title: '数据统计',
total: '总数',
important: '重要',
sources: '来源分布',
categories: '分类分布',
trend: '趋势分析',
},
report: {
daily: '每日简报',
weekly: '每周简报',
generate: '生成报告',
download: '下载报告',
},
status: {
online: '在线',
offline: '离线',
scraping: '抓取中',
idle: '空闲',
},
actions: {
refresh: '刷新',
export: '导出',
subscribe: '订阅',
share: '分享',
},
time: {
justNow: '刚刚',
minutesAgo: '{n}分钟前',
hoursAgo: '{n}小时前',
daysAgo: '{n}天前',
},
},
en: {
app: {
title: 'Alpha-Radar Intelligence Engine',
subtitle: 'Web3/Crypto News Aggregation + AI Classification + Multi-channel Push',
},
nav: {
home: 'Home',
news: 'News',
stats: 'Stats',
settings: 'Settings',
},
news: {
title: 'Intelligence List',
source: 'Source',
category: 'Category',
importance: 'Importance',
publishedAt: 'Published',
search: 'Search intelligence...',
noData: 'No data available',
loadMore: 'Load more',
},
stats: {
title: 'Statistics',
total: 'Total',
important: 'Important',
sources: 'Source Distribution',
categories: 'Category Distribution',
trend: 'Trend Analysis',
},
report: {
daily: 'Daily Report',
weekly: 'Weekly Report',
generate: 'Generate Report',
download: 'Download Report',
},
status: {
online: 'Online',
offline: 'Offline',
scraping: 'Scraping',
idle: 'Idle',
},
actions: {
refresh: 'Refresh',
export: 'Export',
subscribe: 'Subscribe',
share: 'Share',
},
time: {
justNow: 'Just now',
minutesAgo: '{n} minutes ago',
hoursAgo: '{n} hours ago',
daysAgo: '{n} days ago',
},
},
};
let currentLocale = 'zh';
function setLocale(locale) {
if (translations[locale]) {
currentLocale = locale;
return true;
}
return false;
}
function getLocale() {
return currentLocale;
}
function t(key, params = {}) {
const keys = key.split('.');
let value = translations[currentLocale];
for (const k of keys) {
if (value && typeof value === 'object') {
value = value[k];
} else {
return key;
}
}
if (typeof value === 'string') {
return value.replace(/\{(\w+)\}/g, (_, k) => params[k] ?? `{${k}}`);
}
return key;
}
function getTranslations(locale = null) {
return translations[locale || currentLocale] || translations.zh;
}
function getSupportedLocales() {
return Object.keys(translations);
}
module.exports = {
setLocale,
getLocale,
t,
getTranslations,
getSupportedLocales,
translations,
};