Skip to content

Added i18n component and related scripts #1082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e82194a
integrated i18n into sicp repository
Mar 12, 2025
7e793de
Add .env to .gitignore
Mar 12, 2025
098de27
attempt to create a translate function that attempts to recursively s…
Mar 18, 2025
10856a1
Refactor translate function to improve XML error handling and update …
Mar 18, 2025
4922e98
Update .gitignore and refactor translation logic to use recurTranslat…
Mar 18, 2025
9f21e76
updated splitting logic to concat orphaned texts
Mar 18, 2025
29f1441
Refactor XML parsing logic to use strict mode and enhance text escaping
Mar 18, 2025
f0316dc
Fix error handling in recursivelyTranslate function and remove debug log
Mar 18, 2025
e45ede2
Refactor recursion logic in translate function to improve orphaned te…
Mar 18, 2025
ba88b63
Enhance translation performance by measuring execution time and refac…
Mar 18, 2025
d443ffb
Refactor async execution in fancyName function and improve error hand…
Mar 18, 2025
da52eb5
Refactor XML escaping logic to use strongEscapeXML for improved secur…
Mar 18, 2025
3370e50
Refactor segment handling in recursivelyTranslate function to improve…
Mar 19, 2025
d48e425
Add .gitignore for node_modules and update translation logic to handl…
yihao03 Mar 28, 2025
806a152
update lockfile
coder114514 Apr 1, 2025
3329c54
reorganised file structure and yarn prepare json to translate all lan…
yihao03 Apr 10, 2025
7a835c5
Merge branch 'master' of https://github.com/yihao03/sicp
yihao03 Apr 10, 2025
d110429
Fix file path resolution in translate function and update package man…
yihao03 Apr 10, 2025
a115312
Refactor translation logic to simplify segment handling and improve r…
yihao03 Apr 11, 2025
89841d6
Enhance error handling and logging in translation process, streamline…
yihao03 Apr 11, 2025
b37b503
added proper error logging and reporting. added ability to skip trans…
yihao03 Apr 12, 2025
48fe8df
modified index.js to properly handle updated repository structure. Ad…
yihao03 Apr 12, 2025
8e0e318
added troubleshoot toggle that skips calling
yihao03 Apr 12, 2025
f0c039f
Add references, index preface, and making section for SICP JS project
yihao03 Apr 12, 2025
b9ce30a
Refactor translation logic to improve handling of SCHEME and SCHEMEIN…
yihao03 Apr 12, 2025
5f23def
added filename to json error logging
yihao03 Apr 12, 2025
429cff5
updated to remove file search annotation generated by api calls
yihao03 Apr 12, 2025
a28c5f8
ran prettier
yihao03 Apr 12, 2025
c3be2c0
refined troubleshoot toggle, temporarily removed problemtic skipping …
yihao03 Apr 13, 2025
74a4cf5
Updated to delete uploaded dictionary files
yihao03 Apr 13, 2025
3578a86
Optimized responses error handling and translation logic for cost con…
yihao03 Apr 13, 2025
162b943
Merge branch 'master' into master
yihao03 Apr 13, 2025
462bf46
added ability to translate specific languages and/or sections through…
yihao03 Apr 14, 2025
cb6dce0
now returns full path to the files
yihao03 Apr 14, 2025
b40d775
Merge branch 'master' of https://github.com/yihao03/sicp
yihao03 Apr 14, 2025
e807621
Moved targetted translation language here
yihao03 Apr 14, 2025
851b85c
renamed cn folder to proper language code (zn)
yihao03 Apr 14, 2025
0b4097a
update deploy-pages.yml to clone from `translated_xmls`
coder114514 Apr 14, 2025
63e0d21
update the CLI of yarn trans
coder114514 Apr 14, 2025
9caca4b
add yarn trans test and fixed other bugs
coder114514 Apr 14, 2025
dec7c1d
updated .env.example to reflect new parameters
yihao03 Apr 15, 2025
4ca88aa
added new ignored tags
yihao03 Apr 15, 2025
8989ffa
add workflows for ai translations
coder114514 Apr 15, 2025
f87d8af
add back needsTranslation which is invoked by yarn trans abs
coder114514 Apr 15, 2025
8cb0bd5
Merge branch 'sicp_i18n' into i18n_gh_actions
coder114514 Apr 15, 2025
3637fef
replaced problematic translations
yihao03 Apr 16, 2025
da45b5e
fix bugs
coder114514 Apr 16, 2025
0483909
Merge branch 'master' of https://github.com/yihao03/sicp
yihao03 Apr 16, 2025
28ded1d
Merge branch 'master' of https://github.com/yihao03/sicp
yihao03 Apr 16, 2025
ffdb9ae
corrected minor bugs
yihao03 Apr 16, 2025
ee03f0b
renamed folder to use longer language code
yihao03 Apr 16, 2025
9ca1eae
refactor: clean up code and improve error logging in recurTranslate.ts
yihao03 May 1, 2025
2653bd9
moved constants to config.ts
yihao03 May 1, 2025
e6a13cf
refactor: update OpenAI import and enhance error handling for file st…
yihao03 May 1, 2025
48d7c93
ran prettier
yihao03 May 1, 2025
ba25b24
ran prettier
yihao03 May 1, 2025
f994790
refactored recurTranslate and split functionalities to different files
yihao03 May 1, 2025
4c118b7
chore: update dotenv and openai dependencies to latest versions
yihao03 May 1, 2025
23da84c
ran prettier
yihao03 May 1, 2025
12531b3
refactored index.ts
yihao03 May 1, 2025
cdf91c6
renamed files
yihao03 May 1, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/deploy-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ jobs:
sudo apt-get install -y texlive texlive-fonts-extra latexmk
- name: Fetch Yarn dependencies
run: yarn install
- name: Clone translated_xmls
run: |
git clone -b translated_xmls https://github.com/source-academy/sicp.git translated_xmls
mv translated_xmls/* xml/
rm -r translated_xmls
- name: Build
run: |
set -euxo pipefail
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/translate-changed.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
on:
workflow_dispatch:
workflow_call:

concurrency:
group: translate-changed
cancel-in-progress: true

jobs:
translate-changed:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: cd
run: |
cd i18n
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Fetch Yarn Dependencies
run: |
yarn install
- name: Clone translated_xmls
run: |
git clone -b translated_xmls https://github.com/source-academy/sicp.git translation_output
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46
with:
files: |
xml/**.xml
- name: Create .env
run: |
touch .env
echo API_MODEL=gpt-4.1-mini >> .env
echo API_KEY=${{ secrets.OPENAI_KEY }} >> .env
# echo API_KEY=${{ secrets.OPENAI_KEY2 }} >> .env
- name: Translate Changed Files
if: steps.changed-files.outputs.anychanged == 'true'
env:
CHANGED_FILES: ${{ steps.changed_files.outputs.all_changed_files }}
run: |
npx tsx index.ts "${CHANGED_FILES[@]}"
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./translation_output
force_orphan: false # leave the possibility for direct modification on translated xmls
39 changes: 39 additions & 0 deletions .github/workflows/translate-everything.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
workflow_dispatch:
worflow_call:

concurrency:
group: translate-everything
cancel-in-progress: true

jobs:
translate-everything:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: cd
run: |
cd i18n
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
- name: Fetch Yarn Dependencies
run: |
yarn install
- name: Create .env
run: |
touch .env
echo API_MODEL=gpt-4.1-mini >> .env
echo API_KEY=${{ secrets.OPENAI_KEY }} >> .env
# echo API_KEY=${{ secrets.OPENAI_KEY2 }} >> .env
- name: Run Translation
run: |
npx tsx index.ts
- name: Deploy
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./translation_output
force_orphan: false # leave the possiblity for direct modification on translated xmls
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ test_node_env/expect.txt
test_node_env/result.txt
test_node_env/node_modules
.DS_Store
.env
*.icloud

/xml_*
/logs
28 changes: 28 additions & 0 deletions i18n/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
API_KEY=

# Model to be used for translation
# ensure that selected assistant supports file search API
# models that are tried and shown to work includes: o3-mini, 4o and 4o mini
AI_MODEL=gpt-4.1-nano

# maximum number of characters to be sent for translation per batch, default: 3000
# smaller number of characters could lead to greater translation quality
# but worse continuity
MAX_LEN=5000

#Optional, only specify if calling alternative LLM provider
# Note: We require the Assistant API which only OpenAI provides as of 13 April 2025
AI_BASEURL=

# maximum number of concurent translations that are allowed
# if unspecified default to 5
MAX_TRANSLATION_NO=10

# Number of previous messages to be referred to in a thread for LLM Translation, if unspecified, default to 3
# Higher context size might lead to greater continuity in translation but higher cost and lower speed.
CONTEXT=3

# Number of token per query which when exceeded will log an error
# Formula to derive an adequate value: MAX_LEN * CONTEXT * k, where k is a constant
# Recommended k = 1.5
TOKEN_WARNING=7000
2 changes: 2 additions & 0 deletions i18n/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/translation_output
1 change: 1 addition & 0 deletions i18n/ai_files/zh_CN/dictionary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function: 函数
Loading
Loading