Skip to content

Commit 3e5f184

Browse files
committed
feat: localize the site config strings
Making use of the undocumented workaround made available at [1]. [1]: facebook/docusaurus#8677
1 parent cb1fce9 commit 3e5f184

1 file changed

Lines changed: 48 additions & 10 deletions

File tree

docusaurus.config.ts

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,48 @@ const commonRehypePlugins = [
3535
],
3636
]
3737

38+
// i18n workarounds
39+
// see https://github.com/facebook/docusaurus/issues/4542
40+
// and https://github.com/facebook/docusaurus/pull/8677
41+
const defaultLocale = 'zh-Hans'
42+
process.env.DOCUSAURUS_CURRENT_LOCALE ??= defaultLocale
43+
if (process.env.DOCUSAURUS_CURRENT_LOCALE == 'undefined') {
44+
// this is also happening for some reason...
45+
process.env.DOCUSAURUS_CURRENT_LOCALE = defaultLocale
46+
}
47+
48+
const configStringsTranslations = {
49+
en: {
50+
title: 'AREWELOONGYET?',
51+
tagline: 'Your one-stop portal for following LoongArch upstream work.',
52+
logoPath: 'img/logo-en.svg',
53+
twilTitle: 'This Week in LoongArch',
54+
twilDescription:
55+
'This Week in LoongArch (TWiL) is a weekly newsletter covering the latest developments in the LoongArch community, publishing every Monday.',
56+
siteNewsTitle: 'Site news',
57+
siteNewsDescription:
58+
'News on the development and operations of the AREWELOONGYET? site.',
59+
},
60+
'zh-Hans': {
61+
title: '咱龙了吗?',
62+
tagline: '一站式了解 LoongArch 的上游生态建设。',
63+
logoPath: 'img/logo.svg',
64+
twilTitle: '每周一龙',
65+
twilDescription:
66+
'龙架构新世界生态建设周报《每周一龙》(This Week in LoongArch)。每周一都为大家报道 LoongArch 社区最前线的第一手新鲜资讯!',
67+
siteNewsTitle: '本站动态',
68+
siteNewsDescription: '《咱龙了吗?》网站本身的开发、运营动态。',
69+
},
70+
}
71+
72+
const localizeConfigString = (key: string) => {
73+
const locale = process.env.DOCUSAURUS_CURRENT_LOCALE ?? defaultLocale
74+
return configStringsTranslations[locale][key]
75+
}
76+
3877
const config: Config = {
39-
title: '咱龙了吗?',
40-
tagline: '一站式了解 LoongArch 的上游生态建设。',
78+
title: localizeConfigString('title'),
79+
tagline: localizeConfigString('tagline'),
4180
url: 'https://areweloongyet.com',
4281
baseUrl: '/',
4382
onBrokenLinks: 'throw',
@@ -55,8 +94,8 @@ const config: Config = {
5594
// metadata like html lang. For example, if your site is Chinese, you may want
5695
// to replace "en" with "zh-Hans".
5796
i18n: {
58-
defaultLocale: 'zh-Hans',
59-
locales: ['zh-Hans', 'en'],
97+
defaultLocale: defaultLocale,
98+
locales: [defaultLocale, 'en'],
6099
},
61100

62101
future: {
@@ -157,9 +196,8 @@ const config: Config = {
157196
id: 'blog-newsletter',
158197
routeBasePath: 'newsletter',
159198
path: './newsletter',
160-
blogTitle: '每周一龙',
161-
blogDescription:
162-
'龙架构新世界生态建设周报《每周一龙》(This Week in LoongArch)。每周一都为大家报道 LoongArch 社区最前线的第一手新鲜资讯!',
199+
blogTitle: localizeConfigString('twilTitle'),
200+
blogDescription: localizeConfigString('twilDescription'),
163201
editUrl:
164202
'https://github.com/loongson-community/areweloongyet/edit/main',
165203
beforeDefaultRemarkPlugins: commonBeforeDefaultRemarkPlugins,
@@ -182,8 +220,8 @@ const config: Config = {
182220
rehypePlugins: commonRehypePlugins,
183221
},
184222
blog: {
185-
blogTitle: '本站动态',
186-
blogDescription: '《咱龙了吗?》网站本身的开发、运营动态。',
223+
blogTitle: localizeConfigString('siteNewsTitle'),
224+
blogDescription: localizeConfigString('siteNewsDescription'),
187225
showReadingTime: true,
188226
// Please change this to your repo.
189227
// Remove this to remove the "edit this page" links.
@@ -221,7 +259,7 @@ const config: Config = {
221259
title: '',
222260
logo: {
223261
alt: 'My Site Logo',
224-
src: 'img/logo.svg',
262+
src: localizeConfigString('logoPath'),
225263
},
226264
items: [
227265
{

0 commit comments

Comments
 (0)