Skip to content

Commit 0483909

Browse files
committed
Merge branch 'master' of https://github.com/yihao03/sicp
2 parents 3637fef + 8cb0bd5 commit 0483909

File tree

13 files changed

+219
-418
lines changed

13 files changed

+219
-418
lines changed

.github/workflows/deploy-pages.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ jobs:
3030
sudo apt-get install -y texlive texlive-fonts-extra latexmk
3131
- name: Fetch Yarn dependencies
3232
run: yarn install
33+
- name: Clone translated_xmls
34+
run: |
35+
git clone -b translated_xmls https://github.com/source-academy/sicp.git translated_xmls
36+
mv translated_xmls/* xml/
37+
rm -r translated_xmls
3338
- name: Build
3439
run: |
3540
set -euxo pipefail
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
on:
2+
workflow_dispatch:
3+
workflow_call:
4+
5+
concurrency:
6+
group: translate-changed
7+
cancel-in-progress: true
8+
9+
jobs:
10+
translate-changed:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: cd
15+
run: |
16+
cd i18n
17+
- name: Use Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
cache: yarn
22+
- name: Fetch Yarn Dependencies
23+
run: |
24+
yarn install
25+
- name: Clone translated_xmls
26+
run: |
27+
git clone -b translated_xmls https://github.com/source-academy/sicp.git translation_output
28+
- name: Get Changed Files
29+
id: changed-files
30+
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46
31+
with:
32+
files: |
33+
xml/**.xml
34+
- name: Create .env
35+
run: |
36+
touch .env
37+
echo API_MODEL=gpt-4.1-mini >> .env
38+
echo API_KEY=${{ secrets.OPENAI_KEY }} >> .env
39+
# echo API_KEY=${{ secrets.OPENAI_KEY2 }} >> .env
40+
- name: Translate Changed Files
41+
if: steps.changed-files.outputs.anychanged == 'true'
42+
env:
43+
CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
44+
run: |
45+
npx tsx index.ts "${CHANGED_FILES[@]}"
46+
- name: Deploy
47+
uses: peaceiris/actions-gh-pages@v4
48+
with:
49+
github_token: ${{ secrets.GITHUB_TOKEN }}
50+
publish_dir: ./translation_output
51+
force_orphan: false # leave the possibility for direct modification on translated xmls
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on:
2+
workflow_dispatch:
3+
worflow_call:
4+
5+
concurrency:
6+
group: translate-everything
7+
cancel-in-progress: true
8+
9+
jobs:
10+
translate-everything:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: cd
15+
run: |
16+
cd i18n
17+
- name: Use Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: 20
21+
cache: yarn
22+
- name: Fetch Yarn Dependencies
23+
run: |
24+
yarn install
25+
- name: Create .env
26+
run: |
27+
touch .env
28+
echo API_MODEL=gpt-4.1-mini >> .env
29+
echo API_KEY=${{ secrets.OPENAI_KEY }} >> .env
30+
# echo API_KEY=${{ secrets.OPENAI_KEY2 }} >> .env
31+
- name: Run Translation
32+
run: |
33+
npx tsx index.ts
34+
- name: Deploy
35+
uses: peaceiris/actions-gh-pages@v4
36+
with:
37+
github_token: ${{ secrets.GITHUB_TOKEN }}
38+
publish_dir: ./translation_output
39+
force_orphan: false # leave the possiblity for direct modification on translated xmls

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ test_node_env/node_modules
1313
.env
1414
*.icloud
1515

16-
/xml_*
16+
/xml_*
17+
/logs

dictionary/short.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

i18n/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/node_modules
1+
/node_modules
2+
/translation_output

i18n/ai_files/zh_CN/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
function: 函数
File renamed without changes.

i18n/controllers/gitComm.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

i18n/controllers/recurTranslate.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,19 @@ async function translate(langCode: string, filePath: string): Promise<void> {
8484
try {
8585
// Use the provided file path directly without modification
8686
const input_path = filePath;
87-
const language = languageNames.of(langCode);
87+
const language = languageNames.of(langCode.replace('_', '-'));
8888

8989
if (language === undefined) {
9090
throw new Error('Undefined language');
9191
}
9292

93-
if (!troubleshoot) assistant = await createAssistant(language, ai as any);
93+
if (!troubleshoot) assistant = await createAssistant(langCode, language, ai as any);
9494

95-
96-
// Generate output path by replacing "/en/" with "/cn/" in the path
95+
// Generate output path by replacing "/en/" with "/../i18n/translation_output/zh_CN/" in the path
9796
const output_path = filePath.replace(
9897
path.sep + "en" + path.sep,
99-
path.sep + langCode + path.sep
98+
path.sep + ".." + path.sep + "i18n" + path.sep + "translation_output" + path.sep + langCode + path.sep
10099
);
101-
102-
103100

104101
const translated: string = await recursivelyTranslate(
105102
language,

0 commit comments

Comments
 (0)