11import PathGenerator from "./controllers/path.ts" ;
22import translate , { getFileErrors } from "./controllers/recurTranslate.ts" ;
3- import fs from "fs" ;
3+ import fs , { Dirent } from "fs" ;
44import util from "util" ;
55import path from "path" ;
66import { fileURLToPath } from "url" ;
77import { dirname } from "path" ;
88import OpenAI from "openai" ;
9+ import { max_trans_num , translationSummaryPrefix } from "./config.ts" ;
910
1011// Get the directory name of the current module
1112const __filename = fileURLToPath ( import . meta. url ) ;
1213const __dirname = dirname ( __filename ) ;
1314
1415const 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;
2627let processedCount = 0 ;
2728let 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
3231async 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
0 commit comments