Skip to content

Consolidate #1089

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 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
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ test_node_env/expect.txt
test_node_env/result.txt
test_node_env/node_modules
.DS_Store
.env
*.icloud

/xml_*
3,214 changes: 3,214 additions & 0 deletions dictionary/cn.txt

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions i18n/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
API_KEY=
AI_MODEL=gpt-4o
# maximum number of characters to be sent for translation per batch
MAX_LEN=2000
#Optional
AI_BASEURL=
# maximum number of concurent translations that are allowed
MAX_TRANSLATION_NO=10
1 change: 1 addition & 0 deletions i18n/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
54 changes: 54 additions & 0 deletions i18n/controllers/gitComm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Octokit } from "octokit";
import dotenv from "dotenv";
import fs from "fs";
import path from "path";
dotenv.config();

if (process.env.GITHUB_OWNER === undefined || process.env.GITHUB_REPO === undefined) {
throw Error("Please specify GITHUB_OWNER, GITHUB_REPO to pull EN XML from!");
}

// initialize GitHub API
const octokit = new Octokit();

async function getSource(filePath: string): Promise<string> {
let toTranslate;

try {
const result = await octokit.request(
"GET /repos/{owner}/{repo}/contents/{path}",
{
owner: process.env.GITHUB_OWNER!,
repo: process.env.GITHUB_REPO!,
path: filePath,
headers: {
accept: "application/vnd.github.raw+json",
},
}
);

toTranslate = result.data;
const output_dir = path.join(import.meta.dirname, "../../ori");

// Ensure directory exists
const dir = path.dirname(path.join(output_dir, filePath));
fs.mkdirSync(dir, { recursive: true });

const fullPath = path.resolve(path.join(output_dir, filePath));
fs.writeFileSync(fullPath, toTranslate);

console.log(
`Successfully retrieved ${filePath} from GitHub, retrieval status: ${result.status}`
);
} catch (error) {
console.log(
`Error retrieving ${filePath} from GitHub.\n Status: ${error.status}.\n Rate limit remaining: ${error.response.headers["x-ratelimit-remaining"]}.\n Message: ${error.response.data.message}`
);
}

return toTranslate as string;
}

async function commitTranslated() {}

export { getSource, commitTranslated };
19 changes: 19 additions & 0 deletions i18n/controllers/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default function PathGenerator(path: string) {
const pathArray: string[] = path.split(".");
let gitPath: string = "";
const gitPathPrefix: string[] = ["chapter", "section", "subsection"];

let i = 0;
const len = pathArray.length;

while (i <= len && i < 3) {
if (i === len) {
gitPath += `/${gitPathPrefix[i - 1]}${pathArray[i - 1]}`;
} else {
gitPath += `/${gitPathPrefix[i]}${pathArray[i]}`;
}
i++;
}

return gitPath + ".xml";
}
Loading
Loading