Skip to content

Commit af93a89

Browse files
committed
refactor: declare translations in plugin
1 parent e5f736e commit af93a89

File tree

13 files changed

+147
-39
lines changed

13 files changed

+147
-39
lines changed

i18n/en/code.json

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
},
126126
"theme.docs.versions.latestVersionSuggestionLabel": {
127127
"message": "For up-to-date documentation, see the {latestVersionLink} ({versionLabel}).",
128-
"description": "The label userd to tell the user that he's browsing an unmaintained doc version"
128+
"description": "The label used to tell the user to check the latest version"
129129
},
130130
"theme.docs.versions.latestVersionLinkLabel": {
131131
"message": "latest version",
@@ -156,52 +156,94 @@
156156
"description": "The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation"
157157
},
158158
"frontpage.button": {
159-
"message": "Read more",
160-
"description": "The button that navigates to the docs"
159+
"message": "Read more"
161160
},
162161
"frontpage.sec1": {
163-
"message": "Our activities",
164-
"description": "The first section title"
162+
"message": "Our activities"
165163
},
166164
"frontpage.sec1.item1.title": {
167165
"message": "Web development",
168166
"description": "Title to the first item in the activities section"
169167
},
170168
"frontpage.sec1.item1": {
171-
"message": "At Computerization, learn front-end frameworks including {link1} and {link2}, develop collaboratively on GitHub, and utilize the skills accrued to create your own personal page. Engage in the club's platform building and demonstrate your unique creativity!",
172-
"description": "The first item in the activities section"
169+
"message": "At Computerization, learn front-end frameworks including {link1} and {link2}, develop collaboratively on GitHub, and utilize the skills accrued to create your own personal page. Engage in the club's platform building and demonstrate your unique creativity!"
173170
},
174171
"frontpage.sec1.item2.title": {
175172
"message": "Algorithm contests",
176173
"description": "Title to the second item in the activities section"
177174
},
178175
"frontpage.sec1.item2": {
179-
"message": "At Computerization, share your coding experience with other contest masters, and probe deeper into data structures and algorithms. Prepare for NOIP China, and join LeetCode or Luogu contests. Improve yourself through trials and tribulations!",
180-
"description": "The second item in the activities section"
176+
"message": "At Computerization, share your coding experience with other contest masters, and probe deeper into data structures and algorithms. Prepare for NOIP China, and join LeetCode or Luogu contests. Improve yourself through trials and tribulations!"
181177
},
182178
"frontpage.sec1.item3.title": {
183179
"message": "Explore artificial intelligence",
184180
"description": "Title to the third item in the activities section"
185181
},
186182
"frontpage.sec1.item3": {
187-
"message": "At Computeriztaion, learn the cutting-edge technology, discover the secrets behind artificial intelligence and machine learning, design a neural network yourself, and train it to realize any kind of your craziest dreams!",
188-
"description": "The third item in the activities section"
183+
"message": "At Computeriztaion, learn the cutting-edge technology, discover the secrets behind artificial intelligence and machine learning, design a neural network yourself, and train it to realize any kind of your craziest dreams!"
189184
},
190185
"frontpage.sec1.imgsrc": {
191-
"message": "Image source: ",
192-
"description": "The declaration of image source"
186+
"message": "Image source: "
193187
},
194188
"frontpage.sec1.imgsrc.link": {
195-
"message": "Docusaurus official documentation",
196-
"description": "The link name of image source"
189+
"message": "Docusaurus official documentation"
197190
},
198191
"frontpage.sec2.title": {
199-
"message": "What's new",
200-
"description": "The second section title"
192+
"message": "What's new"
201193
},
202194
"frontpage.sec2.item1": {
203-
"message": "Our homepage is officially here!",
204-
"description": "The first item in the What's new section"
195+
"message": "Our homepage is officially here!"
196+
},
197+
"frontpage.sec2.item2": {
198+
"message": "C 社 2022 届开始招新,欢迎你的加入!"
199+
},
200+
"theme.ErrorPageContent.title": {
201+
"message": "This page crashed.",
202+
"description": "The title of the fallback page when the page crashed"
203+
},
204+
"theme.ErrorPageContent.tryAgain": {
205+
"message": "Try again",
206+
"description": "The label of the button to try again when the page crashed"
207+
},
208+
"theme.BackToTopButton.buttonAriaLabel": {
209+
"message": "Scroll back to top",
210+
"description": "The ARIA label for the back to top button"
211+
},
212+
"theme.blog.sidebar.navAriaLabel": {
213+
"message": "Blog recent posts navigation",
214+
"description": "The ARIA label for recent posts in the blog sidebar"
215+
},
216+
"theme.DocSidebarItem.toggleCollapsedCategoryAriaLabel": {
217+
"message": "Toggle the collapsible sidebar category '{label}'",
218+
"description": "The ARIA label to toggle the collapsible sidebar category"
219+
},
220+
"theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel": {
221+
"message": "← Back to main menu",
222+
"description": "The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)"
223+
},
224+
"theme.navbar.mobileVersionsDropdown.label": {
225+
"message": "Versions",
226+
"description": "The label for the navbar versions dropdown on mobile view"
227+
},
228+
"theme.TOCCollapsible.toggleButtonLabel": {
229+
"message": "On this page",
230+
"description": "The label used by the button on the collapsible TOC component"
231+
},
232+
"theme.blog.archive.title": {
233+
"message": "Archive",
234+
"description": "The page & hero title of the blog archive page"
235+
},
236+
"theme.blog.archive.description": {
237+
"message": "Archive",
238+
"description": "The page & hero description of the blog archive page"
239+
},
240+
"theme.docs.tagDocListPageTitle.nDocsTagged": {
241+
"message": "One doc tagged|{count} docs tagged",
242+
"description": "Pluralized label for \"{count} docs tagged\". Use as much plural forms (separated by \"|\") as your language support (see https://www.unicode.org/cldr/cldr-aux/charts/34/supplemental/language_plural_rules.html)"
243+
},
244+
"theme.docs.tagDocListPageTitle": {
245+
"message": "{nDocsTagged} with \"{tagName}\"",
246+
"description": "The title of the page for a docs tag"
205247
},
206248
"alumni.title": {
207249
"message": "Our Alumni",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"title": {
3+
"message": "Blog",
4+
"description": "The title for the blog used in SEO"
5+
},
6+
"description": {
7+
"message": "Blog",
8+
"description": "The description for the blog used in SEO"
9+
},
10+
"sidebar.title": {
11+
"message": "Recent posts",
12+
"description": "The label for the left sidebar"
13+
}
14+
}

i18n/en/docusaurus-plugin-content-docs/current.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@
1414
"sidebar.docs.category.Enspire": {
1515
"message": "Enspire",
1616
"description": "The label for category Enspire in sidebar docs"
17+
},
18+
"sidebar.docs.category.Infrastructure": {
19+
"message": "Infrastructure",
20+
"description": "The label for category Infrastructure in sidebar docs"
1721
}
1822
}

i18n/en/docusaurus-theme-classic/footer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
{
22
"link.title.文档": {
33
"message": "Docs",
4-
"description": "The title of the footer links column with title=Docs in the footer"
4+
"description": "The title of the footer links column with title=文档 in the footer"
55
},
66
"link.title.社区": {
77
"message": "Community",
8-
"description": "The title of the footer links column with title=Community in the footer"
8+
"description": "The title of the footer links column with title=社区 in the footer"
99
},
1010
"link.title.社交": {
1111
"message": "Social",
12-
"description": "The title of the footer links column with title=Social in the footer"
12+
"description": "The title of the footer links column with title=社交 in the footer"
1313
},
1414
"link.item.label.文档": {
1515
"message": "Docs",
16-
"description": "The label of footer link with label=Docs linking to docs/about-us"
16+
"description": "The label of footer link with label=文档 linking to docs/about-us"
1717
},
1818
"link.item.label.GitHub": {
1919
"message": "GitHub",
2020
"description": "The label of footer link with label=GitHub linking to https://github.com/Computerization"
2121
},
2222
"link.item.label.博客": {
2323
"message": "Blog",
24-
"description": "The label of footer link with label=Blog linking to blog"
24+
"description": "The label of footer link with label=博客 linking to blog"
2525
},
2626
"copyright": {
2727
"message": "Copyright © 2021 Computerization. Built with Docusaurus.",

plugins/docusaurus-plugin-alumni/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
"main": "lib/index.js",
66
"types": "src/types.d.ts",
77
"scripts": {
8-
"build": "tsc && node copyUntypedFiles",
9-
"watch": "node copyUntypedFiles && tsc --watch",
8+
"build": "yarn build:server && yarn build:browser && yarn build:copy && yarn build:format",
9+
"build:server": "tsc --project tsconfig.server.json",
10+
"build:browser": "tsc --project tsconfig.browser.json",
11+
"build:copy": "node copyUntypedFiles.js",
12+
"build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\"",
1013
"postinstall": "yarn build"
1114
},
1215
"dependencies": {

plugins/docusaurus-plugin-alumni/src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
import fs from 'fs/promises';
23
import {
34
getPluginI18nPath,
45
normalizeUrl,
@@ -14,13 +15,8 @@ export default function pluginAlumni(context: LoadContext): Plugin<AlumniData> {
1415
const {
1516
siteDir,
1617
siteConfig: { baseUrl },
17-
generatedFilesDir,
1818
i18n: { currentLocale },
1919
} = context;
20-
const pluginDataDirRoot = path.join(
21-
generatedFilesDir,
22-
'docusaurus-plugin-alumni',
23-
);
2420
return {
2521
name: 'docusaurus-plugin-alumni',
2622
getThemePath() {
@@ -53,11 +49,16 @@ export default function pluginAlumni(context: LoadContext): Plugin<AlumniData> {
5349
component: '@theme/AlumniPage',
5450
exact: true,
5551
modules: {
56-
alumni: `./docusaurus-plugin-alumni/${posixPath(
57-
path.relative(pluginDataDirRoot, alumniData),
58-
)}`,
52+
alumni: alumniData,
5953
},
6054
});
6155
},
56+
async getDefaultCodeTranslationMessages() {
57+
const file = path.join(
58+
__dirname,
59+
`../translations/${context.i18n.currentLocale}.json`,
60+
);
61+
return JSON.parse((await fs.readFile(file)).toString());
62+
},
6263
};
6364
}

plugins/docusaurus-plugin-alumni/src/theme/AlumniPage/index.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,16 @@ export default function Alumni({ alumni }: Props): JSX.Element {
1414
<div className="container margin-vert--lg">
1515
<div className={styles.content}>
1616
<h1>
17-
<Translate id="alumni.title">我们的过往成员</Translate>
17+
<Translate
18+
id="alumni.title"
19+
description="The title of the alumni page">
20+
我们的过往成员
21+
</Translate>
1822
</h1>
1923
<p className="text--large">
2024
<Translate
2125
id="alumni.description"
26+
description="The description of the alumni page"
2227
values={{
2328
link: (
2429
<a href="https://github.com/Computerization/docusaurus/issues">
@@ -34,13 +39,16 @@ export default function Alumni({ alumni }: Props): JSX.Element {
3439
<p style={{ fontSize: '80%' }}>
3540
<Translate
3641
id="alumni.description2"
42+
description="The second paragraph of description of the alumni page"
3743
values={{
3844
link1: (
3945
<a
4046
href="https://github.com/Computerization/Computerization-website/edit/master/alumni/alumni.yml"
4147
target="_blank"
4248
rel="noreferrer noopener">
43-
<Translate id="alumni.description2.link1">
49+
<Translate
50+
id="alumni.description2.link1"
51+
description="The first link">
4452
中文版
4553
</Translate>
4654
</a>
@@ -50,7 +58,9 @@ export default function Alumni({ alumni }: Props): JSX.Element {
5058
href="https://github.com/Computerization/Computerization-website/edit/master/i18n/en/docusaurus-plugin-alumni/alumni.yml"
5159
target="_blank"
5260
rel="noreferrer noopener">
53-
<Translate id="alumni.description2.link2">
61+
<Translate
62+
id="alumni.description2.link2"
63+
description="The second link">
5464
英文版
5565
</Translate>
5666
</a>

plugins/docusaurus-plugin-alumni/src/theme/AlumniTimeline/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export default function AlumniTimeline({ alumni }: Props): JSX.Element {
1919
id={String(classOf)}
2020
href={`#${classOf}`}
2121
className={styles.date}>
22-
<Translate id="alumni.classOf" values={{ classOf }}>
22+
<Translate
23+
id="alumni.classOf"
24+
description="The section label for each class"
25+
values={{ classOf }}>
2326
{'{classOf} 届'}
2427
</Translate>
2528
</a>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"alumni.title": "Our Alumni",
3+
"alumni.description": "If you are an alumnus or an alumna of the Computerization club and would like us to update your listing or link to your homepage, please open an issue or pull request at the {link} repository, or drop us a WeChat message.",
4+
"alumni.description2": "Please take note that there are two places to make edits: {link1} and {link2}.",
5+
"alumni.description2.link1": "the Chinese version",
6+
"alumni.description2.link2": "the English one",
7+
"alumni.classOf": "Class of {classOf}"
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"alumni.title": "我们的过往成员",
3+
"alumni.description": "如果你是信息化社的过往成员,并且希望我们更新你的个人信息或链接,请在 {link} 仓库中提交 issue 或 pull request。你也可以微信联系我们。",
4+
"alumni.description2": "注意,有两处文件需要修改:{link1}和{link2}。",
5+
"alumni.description2.link1": "中文版",
6+
"alumni.description2.link2": "英文版",
7+
"alumni.classOf": "{classOf} 届"
8+
}

0 commit comments

Comments
 (0)