Skip to content

Commit c3be2c0

Browse files
committed
refined troubleshoot toggle, temporarily removed problemtic skipping logic
1 parent a28c5f8 commit c3be2c0

File tree

4 files changed

+2469
-1230
lines changed

4 files changed

+2469
-1230
lines changed

i18n/controllers/recurTranslate.ts

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const MAXLEN = Number(process.env.MAX_LEN) || 3000;
3232

3333
// change to true to avoid calling openai api, useful for troubleshooting
3434
// chunking logic
35-
const troubleshoot = false;
35+
const troubleshoot = true;
3636

3737
// Centralized logging to prevent duplicate messages
3838
const errorMessages = new Set();
@@ -80,7 +80,7 @@ async function translate(language: string, filePath: string): Promise<void> {
8080
// Use the provided file path directly without modification
8181
const input_path = filePath;
8282

83-
assistant = await createAssistant(language, ai as any);
83+
if (!troubleshoot) assistant = await createAssistant(language, ai as any);
8484

8585
// Generate output path by replacing "/en/" with "/cn/" in the path
8686
const output_path = filePath.replace(
@@ -91,7 +91,7 @@ async function translate(language: string, filePath: string): Promise<void> {
9191
const translated: string = await recursivelyTranslate(
9292
language,
9393
input_path,
94-
assistant.id
94+
troubleshoot ? 0 : assistant.id
9595
);
9696

9797
// Ensure directory exists
@@ -287,15 +287,6 @@ async function recursivelyTranslate(
287287
parser.on("opentag", node => {
288288
currentDepth++;
289289

290-
// If we're at depth 2, this is the start of a new segment.
291-
if (
292-
node.name == "SCHEME" ||
293-
node.name == "SCHEMEINLINE" ||
294-
parser._parser.tag === "SCHEME" ||
295-
parser._parser.tag === "SCHEMEINLINE"
296-
)
297-
return;
298-
299290
if (currentDepth === 2 || isRecording) {
300291
isRecording = true;
301292
currentSegment += `<${node.name}${formatAttributes(node.attributes)}>`;
@@ -310,13 +301,6 @@ async function recursivelyTranslate(
310301
parser.on("text", text => {
311302
text = strongEscapeXML(text);
312303

313-
// ignore all scheme contents
314-
if (
315-
parser._parser.tag == "SCHEME" ||
316-
parser._parser.tag == "SCHEMEINLINE"
317-
)
318-
return;
319-
320304
if (isRecording) {
321305
currentSegment += text;
322306
} else {
@@ -331,13 +315,7 @@ async function recursivelyTranslate(
331315
});
332316

333317
parser.on("closetag", tagName => {
334-
if (
335-
tagName !== "SCHEME" &&
336-
tagName !== "SCHEMEINLINE" &&
337-
parser._parser.tag !== "SCHEME" &&
338-
parser._parser.tag !== "SCHEMEINLINE" &&
339-
isRecording
340-
) {
318+
if (isRecording) {
341319
currentSegment += `</${tagName}>`;
342320
}
343321

0 commit comments

Comments
 (0)