-
Notifications
You must be signed in to change notification settings - Fork 4
/
i18n.js
63 lines (57 loc) · 1.36 KB
/
i18n.js
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
// All languages supported by this website.
const supportedLanguages = {
en: 'English',
'zh-hans': '简体中文',
}
const defaultLangKey = 'zh-hans'
const withLangPrefix = (langKey, str) => {
return langKey === defaultLangKey ? str : `/${langKey}${str}`
}
// NOTE: because of this bug of gatsby.js https://github.com/gatsbyjs/gatsby/issues/10058
// Names of category or tag cannot be inferred from `frontmatter`.
// Writers should register pairs of identifier and name here.
const categoryDict = {
en: {
other: 'Other',
'dev-blog': 'Dev Blog'
},
'zh-hans': {
other: '其他',
'dev-blog': '开发日志'
},
}
const tagDict = {
en: {
announcement: 'Announcement',
carousel: 'Carousel',
tutorial: 'Tutorial',
cli: 'CLI',
schematics: 'Schematics',
typescript: 'Typescript',
websocket: 'Websocket'
},
'zh-hans': {
announcement: '公告',
carousel: 'Carousel',
tutorial: '教程',
cli: 'CLI',
schematics: 'Schematics',
typescript: 'Typescript',
websocket: 'Websocket'
},
}
const getCategoryOrTagNameInLang = langKey => {
return identifier => {
return (
categoryDict[langKey][identifier] ||
tagDict[langKey][identifier] ||
'Not Found'
)
}
}
module.exports = {
supportedLanguages,
defaultLangKey,
withLangPrefix,
getTranslator: getCategoryOrTagNameInLang
}