Skip to content

Commit d448d72

Browse files
committed
Merge branch 'sicp_i18n' into i18n_gh_actions
2 parents 4f25151 + ee03f0b commit d448d72

File tree

142 files changed

+12231
-3110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+12231
-3110
lines changed

i18n/index.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import path from "path";
66
import { fileURLToPath } from "url";
77
import { dirname } from "path";
88
import OpenAI from "openai";
9-
import { permission } from "process";
109

1110
// Get the directory name of the current module
1211
const __filename = fileURLToPath(import.meta.url);
@@ -174,10 +173,13 @@ async function setupCleanupHandlers() {
174173
});
175174
}
176175

177-
async function needsTranslation(enFilePath: string, lang: string): boolean {
176+
async function needsTranslation(
177+
enFilePath: string,
178+
lang: string
179+
): Promise<boolean> {
178180
const cnFilePath = enFilePath.replace(
179181
path.sep + "en" + path.sep,
180-
path.sep + ".." + path.sep + "i18n" + path.sep + "translation_output" + path.sep + lang + path.sep
182+
path.sep + lang + path.sep
181183
);
182184
try {
183185
const cnStats = await fs.promises.stat(cnFilePath);
@@ -214,11 +216,18 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
214216
return xmlFiles;
215217
}
216218

219+
export default async function fancyName(path: string, language: string) {
220+
const fullPath = PathGenerator(path);
221+
await translate(language, fullPath);
222+
}
223+
217224
(async () => {
218225
await setupCleanupHandlers();
219226

220227
try {
221-
const languages: string[] = await getDirectories(path.join(__dirname, "ai_files"));
228+
const languages: string[] = await getDirectories(
229+
path.join(__dirname, "ai_files")
230+
);
222231
console.dir(languages);
223232

224233
// Get the absolute path to the xml/en directory using proper path resolution
@@ -231,14 +240,19 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
231240
return;
232241
}
233242
try {
234-
console.log('start translating, may take a while ...');
243+
console.log("start translating, may take a while ...");
235244
const fullPath = PathGenerator(process.argv[3]);
236245
await translate(process.argv[4], fullPath);
237246
} catch (e) {
238-
console.error('test error: ', e);
247+
console.error("test error: ", e);
239248
}
240249
return;
241-
} if (process.argv[2] === "all" || process.argv.length <= 2 || process.argv[2] === "abs") {
250+
}
251+
if (
252+
process.argv[2] === "all" ||
253+
process.argv.length <= 2 ||
254+
process.argv[2] === "abs"
255+
) {
242256
if (process.argv[2] === "abs") {
243257
absent = true;
244258
}
@@ -274,7 +288,9 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
274288
batch.map(async file => {
275289
if (absent) {
276290
if (!(await needsTranslation(file, lang))) {
277-
console.log(`Skipped translation for ${file} to language ${lang} (yarn trans abs)`);
291+
console.log(
292+
`Skipped translation for ${file} to language ${lang} (yarn trans abs)`
293+
);
278294
return { file, success: true };
279295
}
280296
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)