Skip to content

Commit 2653bd9

Browse files
committed
moved constants to config.ts
1 parent 9ca1eae commit 2653bd9

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

i18n/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// maximum permissible concurrent translations
2+
const max_trans_num = Number(process.env.MAX_TRANSLATION_NO) || 5;
3+
4+
// log file configs
5+
const translationSummaryPrefix = "translation-summary";
6+
const jsonSummaryPrefix = "json-summary";
7+
8+
export {max_trans_num, translationSummaryPrefix, jsonSummaryPrefix}

i18n/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import PathGenerator from "./controllers/path.ts";
22
import translate, { getFileErrors } from "./controllers/recurTranslate.ts";
3-
import fs from "fs";
3+
import fs, { Dirent } from "fs";
44
import util from "util";
55
import path from "path";
66
import { fileURLToPath } from "url";
77
import { dirname } from "path";
88
import OpenAI from "openai";
9+
import { max_trans_num, translationSummaryPrefix } from "./config.ts";
910

1011
// Get the directory name of the current module
1112
const __filename = fileURLToPath(import.meta.url);
1213
const __dirname = dirname(__filename);
1314

1415
const readdir = util.promisify(fs.readdir);
15-
const getDirectories = async source =>
16+
const getDirectories = async (source: fs.PathLike) =>
1617
(await readdir(source, { withFileTypes: true }))
1718
.filter(dirent => dirent.isDirectory())
1819
.map(dirent => dirent.name);
@@ -26,8 +27,6 @@ let failureCount = 0;
2627
let processedCount = 0;
2728
let failures: { file: string; error: any }[] = [];
2829

29-
const max_trans_num = Number(process.env.MAX_TRANSLATION_NO) || 5;
30-
3130
// Function to save summary log - can be called from signal handlers
3231
async function saveSummaryLog() {
3332
try {
@@ -115,7 +114,7 @@ Success rate: ${filesToTranslate.length > 0 ? ((successCount / filesToTranslate.
115114
fs.mkdirSync(logDir, { recursive: true });
116115
}
117116

118-
const logPath = path.join(logDir, `translation-summary-${timestamp}.log`);
117+
const logPath = path.join(logDir, `${translationSummaryPrefix}-${timestamp}.log`);
119118
fs.writeFileSync(logPath, summaryLog);
120119
console.log(
121120
`Summary log saved to logs/translation-summary-${timestamp}.log`
@@ -190,7 +189,7 @@ async function needsTranslation(
190189
const enStats = await fs.promises.stat(enFilePath);
191190
return enStats.mtime > cnStats.mtime;
192191
} catch (error) {
193-
return true;
192+
throw error;
194193
}
195194
}
196195

@@ -313,7 +312,6 @@ export default async function fancyName(path: string, language: string) {
313312
if (result.value.success) {
314313
successCount++;
315314
} else {
316-
failureCount++;
317315
failures.push({
318316
file: result.value.file,
319317
error: result.value.error
@@ -324,7 +322,6 @@ export default async function fancyName(path: string, language: string) {
324322
}
325323
} else {
326324
// This is for Promise rejections (should be rare with our error handling)
327-
failureCount++;
328325
failures.push({
329326
file: "Unknown file in batch",
330327
error: result.reason

javascript/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ import { setupSnippetsJs } from "./processingFunctions/processSnippetJs";
3737
import { getAnswers } from "./processingFunctions/processExercisePdf";
3838

3939
// json (for cadet frontend)
40-
import { testIndexSearch } from "./searchRewriteTest";
4140
import { parseXmlJson } from "./parseXmlJson";
4241
import { writeRewritedSearchData } from "./searchRewrite";
4342
import { setupSnippetsJson } from "./processingFunctions/processSnippetJson";
4443
import { createTocJson } from "./generateTocJson";
4544
import { setupReferencesJson } from "./processingFunctions/processReferenceJson";
46-
import { SourceTextModule } from "vm";
47-
import { threadId } from "worker_threads";
48-
import { exitCode } from "process";
45+
import { jsonSummaryPrefix } from "../i18n/config";
4946

5047
export let parseType;
5148
let version;
@@ -407,10 +404,10 @@ async function main() {
407404
fs.mkdirSync(logDir, { recursive: true });
408405
}
409406

410-
const logPath = path.join(logDir, `json-summary-${timestamp}.log`);
407+
const logPath = path.join(logDir, `${jsonSummaryPrefix}-${timestamp}.log`);
411408
fs.writeFileSync(logPath, summaryLog);
412409
console.log(
413-
`Summary log saved to logs/translation-summary-${timestamp}.log`
410+
`Summary log saved to logs/json-summary-${timestamp}.log`
414411
);
415412
} catch (logError) {
416413
console.error("Failed to save log file:", logError);

0 commit comments

Comments
 (0)