@@ -196,30 +196,6 @@ async function findAllXmlFiles(directory: string): Promise<string[]> {
196196 return xmlFiles ;
197197}
198198
199- // Function to check if a file needs translation
200- async function needsTranslation ( enFilePath : string , lang : string ) : Promise < boolean > {
201- // Generate the corresponding cn file path
202- const cnFilePath = enFilePath . replace (
203- path . sep + "en" + path . sep ,
204- path . sep + lang + path . sep
205- ) ;
206-
207- try {
208- // Check if CN file exists
209- const cnStats = await fs . promises . stat ( cnFilePath ) ;
210- if ( ! cnStats . isFile ( ) ) {
211- return true ; // CN path exists but is not a file (unusual case)
212- }
213-
214- // Compare modification times
215- const enStats = await fs . promises . stat ( enFilePath ) ;
216- return enStats . mtime > cnStats . mtime ; // Return true if EN file is newer
217- } catch ( error ) {
218- // If we get an error, it's likely because the CN file doesn't exist
219- return true ; // Need to translate since CN file doesn't exist
220- }
221- }
222-
223199( async ( ) => {
224200 await setupCleanupHandlers ( ) ;
225201
@@ -230,33 +206,35 @@ async function needsTranslation(enFilePath: string, lang: string): Promise<boole
230206 // Get the absolute path to the xml/en directory using proper path resolution
231207 const enDirPath = path . resolve ( __dirname , "../xml/en" ) ;
232208
233- // Find all XML files
234- if ( process . argv [ 2 ] === "all" || process . argv . length <= 2 ) {
209+ if ( process . argv [ 2 ] === "test" ) {
210+ if ( process . argv . length !== 5 ) {
211+ console . log ( "syntax: yarn trans test <section> <lang>" ) ;
212+ return ;
213+ }
214+ try {
215+ console . log ( 'start translating, may take a while ...' ) ;
216+ const fullPath = PathGenerator ( process . argv [ 3 ] ) ;
217+ await translate ( process . argv [ 4 ] , fullPath ) ;
218+ } catch ( e ) {
219+ console . error ( 'test error: ' , e ) ;
220+ }
221+ return ;
222+ } if ( process . argv [ 2 ] === "all" || process . argv . length <= 2 ) {
223+ // Find all XML files
235224 console . log ( `Scanning directory: ${ enDirPath } ` ) ;
236- xmlFiles = await findAllXmlFiles ( enDirPath ) ;
225+ filestoTranslate = await findAllXmlFiles ( enDirPath ) ;
237226 } else {
238- const [ , , ..._xmlFiles ] = process . argv ;
239- xmlFiles = _xmlFiles . map ( file => path . join ( __dirname , ".." , file ) ) ;
227+ const [ , , ...xmlFiles ] = process . argv ;
228+ filesToTranslate = xmlFiles . map ( file => path . join ( __dirname , ".." , file ) ) ;
240229 }
241230
242- console . log ( `Found ${ xmlFiles . length } XML files to check for translation` ) ;
231+ if ( filesToTranslate . length === 0 ) {
232+ console . log ( `No files to translate.` ) ;
233+ return ;
234+ }
235+ console . log ( `${ filesToTranslate . length } files need translation` ) ;
243236
244237 for ( const lang of languages ) {
245- // Filter files that need translation
246- filesToTranslate = [ ] ;
247- for ( const file of xmlFiles ) {
248- if ( await needsTranslation ( file , lang ) ) {
249- filesToTranslate . push ( file as never ) ;
250- }
251- }
252-
253- console . log ( `${ filesToTranslate . length } files need translation` ) ;
254-
255- if ( filesToTranslate . length === 0 ) {
256- console . log ( `No files need translation for ${ lang } .` ) ;
257- return ;
258- }
259-
260238 // Process files in batches to avoid overwhelming the system
261239 const batchSize : number = max_trans_num ;
262240
0 commit comments